首页 \ 问答 \ jQuery幻灯片效果很酷(jQuery Slide Effect is Jerky)

jQuery幻灯片效果很酷(jQuery Slide Effect is Jerky)

所以我试图用jQuery的滑动功能做一种“点击这个来获得新东西”。

基本上我的问题是幻灯片动画是跳跃的,它是由我在.toggleO类中设置的边框引起的。 明显的解决方案是摆脱边界,但我想保留它,所以我想知道在平稳过渡时是否有某种方法可以做到这一点?

这是片段:

$(document).ready(function() {

  $(".toggleO").click(function() {
    $(".toggleO").slideUp(500);
    $(".toggledInfo").slideDown(500);
  });

  $(".toggleC").click(function() {
    $(".toggledInfo").slideUp(500);
    $(".toggleO").slideDown(500);
  });

});
#container {
  width: 500px;
  height: 350px;
  margin: 0px auto;
  font-family: arial;
  font-size: 11px;
  line-height: 13px;
}

#container .toggleO {
  width: 490px;
  height: 340px;
  background-image: url("http://ultraimg.com/images/8de3786443f8af4db9e4a29b8b658c00.jpg");
  cursor: crosshair;
  border: 5px solid black;
}

#container .toggleC {
  width: 500px;
  margin-top: 25px;
  font-family: georgia, times new roman, serif;
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: crosshair;
}

#container .toggledInfo {
  display: none;
}

#container .inside {
  padding: 50px;
  width: 400px;
  height: 260px;
  background-color: #000;
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<div id='container'>
  <div class='toggleO'></div>

  <div class='toggledInfo'>
    <div class='inside'>
      here are links about my thing yep

      <div class='toggleC'>
        close
      </div>
    </div>
  </div>
</div>

这是我小提琴的链接,因为它更容易看到。


So I'm trying to do a kind of "click this to get a new thing" with jQuery's slide function.

Basically my problem is that the slide animation is jumpy and it's caused by the border that I set in the .toggleO class. The obvious solution is to get rid of the border, but I would like to keep it, so I was wondering if there was some way to do that while having a smooth transition?

Here's the snippet:

$(document).ready(function() {

  $(".toggleO").click(function() {
    $(".toggleO").slideUp(500);
    $(".toggledInfo").slideDown(500);
  });

  $(".toggleC").click(function() {
    $(".toggledInfo").slideUp(500);
    $(".toggleO").slideDown(500);
  });

});
#container {
  width: 500px;
  height: 350px;
  margin: 0px auto;
  font-family: arial;
  font-size: 11px;
  line-height: 13px;
}

#container .toggleO {
  width: 490px;
  height: 340px;
  background-image: url("http://ultraimg.com/images/8de3786443f8af4db9e4a29b8b658c00.jpg");
  cursor: crosshair;
  border: 5px solid black;
}

#container .toggleC {
  width: 500px;
  margin-top: 25px;
  font-family: georgia, times new roman, serif;
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: crosshair;
}

#container .toggledInfo {
  display: none;
}

#container .inside {
  padding: 50px;
  width: 400px;
  height: 260px;
  background-color: #000;
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<div id='container'>
  <div class='toggleO'></div>

  <div class='toggledInfo'>
    <div class='inside'>
      here are links about my thing yep

      <div class='toggleC'>
        close
      </div>
    </div>
  </div>
</div>

Here's the link to my fiddle since it's easier to see there.


原文:https://stackoverflow.com/questions/36742579
更新时间:2023-12-26 10:12

最满意答案

您可以创建包含不同步骤的视图类数组。 您可以使用把手模板名称向阵列添加新视图。

App.surveyViews = [];
App.surveyControllers = [];
App.surveyViews['firstStep'] = Em.View.extend({ templateName: 'my-handlebars-template' });
App.surveyControllers['firstStep'] = Em.Controller.extend();

您的路线可以从路线中获取步骤,并使用该路线查找用于connectOutlet的相应视图类和控制器。

step: Em.Route.extend({
    route: '/:step',
    connectOutlets: function(router, context) {
        router.get('applicationController').connectOutlet({ 
            viewClass: App.surveyViews[context.step], 
            controller: App.surveyControllers[context.step].create(),
            context: {}
        });
    }
})

您可以为上下文等添加任何额外的逻辑,但这是基本的想法。


You could create an array of view classes that contains the different steps. You can add new views to the array using the handlebars template name.

App.surveyViews = [];
App.surveyControllers = [];
App.surveyViews['firstStep'] = Em.View.extend({ templateName: 'my-handlebars-template' });
App.surveyControllers['firstStep'] = Em.Controller.extend();

Your route can take in the step from the route and use that to look up the appropriate view class and controller to use for the connectOutlet.

step: Em.Route.extend({
    route: '/:step',
    connectOutlets: function(router, context) {
        router.get('applicationController').connectOutlet({ 
            viewClass: App.surveyViews[context.step], 
            controller: App.surveyControllers[context.step].create(),
            context: {}
        });
    }
})

You can add any extra logic you need for the context, etc., but that would be the basic idea.

相关问答

更多
  • 您的教程使用的是ember-model libray。 但是您当前的代码使用的是ember-data版本1.0.0.beta.x. 两者都是ember的数据库,有类似的api,但是不同。 我建议你使用ember-model libray,这样你就可以完成教程了。 因此,导入ember-model脚本,源位于此处 ,确保它位于ember.js脚本之后,并将模型定义更改为使用ember-model: var attribute = Ember.attr; Tothevoidjs.Secret = Ember. ...
  • 你的问题的根本原因是Handlebars视图助手({{view MyView}})需要一个Ember“class”的路径参数,而不是一个类的实例。 要创建视图类,请使用Ember.View的extend方法。 Handlebars视图助手会实例化你的视图类并将它附加到你的文档中。 有关Ember对象模型的更多信息以及Ember的extend和create方法之间的区别,请参阅此文章: http : //ember-object-model.notlong.com 。 以下是您的示例,并对其进行了一些更改,以 ...
  • 在notes.hbs模板中,您应该能够{{length}} 。 In your notes.hbs template you should be able to do {{length}}.
  • 通过表单上的计算属性执行此操作。 类似于下面的entriesLength并使用它来显示: App.YourForm = App.YourForm.extend ({ entriesLength: function () { return this.get('entries').get('length'); }.property('entries') }); 这也是你如何设置与灯具中的条目的关系: App.Form.FIXTURES = [ { id ...
  • 编辑:这是现在过时,你可以实现以上所有与以下内容: {{input value=objectValue type="number" min="2"}} 过时的答案 您可以指定TextField的类型 Input: {{view Ember.TextField valueBinding="objectValue" type="number"}} 如果您想访问数字字段的额外属性,则可以仅子类Ember.TextField 。 App.NumberField = Ember.TextField.extend({ ...
  • 您可以创建包含不同步骤的视图类数组。 您可以使用把手模板名称向阵列添加新视图。 App.surveyViews = []; App.surveyControllers = []; App.surveyViews['firstStep'] = Em.View.extend({ templateName: 'my-handlebars-template' }); App.surveyControllers['firstStep'] = Em.Controller.extend(); 您的路线可以从路线中获取步 ...
  • 我认为你不应该在准备周数组时改变你的firstDay属性(在计算函数中)。 它会覆盖momentjs状态。 在这种情况下,计算属性应该只读取firstDay属性而不影响对它的更改。 同样在上一周和下周的操作中,您不必创建新的momentjs对象。 例如,您可以轻松地对先前创建的firstDay属性进行操作。 this.get('firstDay').subtract(7, 'days'); 但在这种情况下,momentjs的状态已经改变,但是emberjs没有看到任何变化。 这是因为你的firstDay属 ...
  • App.Typeahead中的控制器指向App.Typeahead的实例,而不是您创建视图的路径中的控制器。 你应该只使用sendAction http://emberjs.jsbin.com/EduDitE/2/edit {{view App.Typeahead}} App.IndexRoute = Ember.Route.extend({ model: function() { return ['red', 'yellow', 'blue']; }, actions:{ ...
  • 如果您正在进行侧载,则需要配置适配器以执行此操作。 DS.RESTAdapter.configure('App.Servicetable', { sideloadAs: 'servicetables' }); 接下来,你需要在club的json中包含servicetable id : "club": { "id": "2", "servicetable_id": 2, ... // Rest of attributes } 当您加载记录时,将它们作为数组传递,并以复数形式设置密钥: ...
  • 三个CSS3D渲染器只是浏览器自己的渲染器的一个简单抽象,因此不应该与使用Ember或jQ操纵DOM元素冲突。 一旦传递给CSS3DObject构造函数,元素的3D变换就会更新,但除此之外,它仍然照常运行。 您可以根据需要操纵其内容并设置样式。 Three's CSS3D renderer is just a thin abstraction of the browsers' own renderer and therefore should not conflict with the manipulati ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。