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
最满意答案
您可以创建包含不同步骤的视图类数组。 您可以使用把手模板名称向阵列添加新视图。
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 ...
-
Ember.js输入字段(Ember.js input fields)[2023-07-29]
编辑:这是现在过时,你可以实现以上所有与以下内容: {{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 } 当您加载记录时,将它们作为数组传递,并以复数形式设置密钥: ...
-
Ember.js与Three.js(Ember.js with Three.js)[2022-06-18]
三个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 ...