jQuery:FadeIn/To 和 SlideDown 新元素
这是我用来将新行推送到容器的一行代码:
this.$el.append(new ItemView(item).render().el);
其中 item
是 Backbone.js 模型,render()
创建和/或修改对象,el
是 html 元素。 (在渲染完成之前,该对象永远不会显示)
我如何保留** new ItemView(item).render()
**并将其存储在变量中,然后淡入淡出并将其滑入(我的容器的底部)?
编辑
请记住,this.$el
是容器元素。
Here is the one line of code I use to push a new row to my container:
this.$el.append(new ItemView(item).render().el);
Where item
is a Backbone.js model, render()
creates and/or modifies the object and el
is the html element. (The object is never displayed until rendering is complete)
How can I keep** new ItemView(item).render()
**and store it in a variable, then fade and slide it into (the bottom) of my container?
Edit
Please keep in mind that this.$el
is the container element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将属性设置为元素 style="display: none;"因此,当您附加它时,它将不可见。
然后添加 exec fadein 函数后,您的元素将可见。
我希望这会有所帮助。
Set attribute to your element style="display: none;" so when you append it it wont be visible.
Then after add exec fadein function and your element will be visible.
I hopt this helps.
在我看来,问题在于让视图的渲染方法返回视图。
你的视图可能看起来像这样:
然后在某个地方你有一个方法来创建视图并将其附加到 DOM。
问题是必须调用 render() 才能访问视图的元素......
想想看,当模型发生更改时,视图将再次渲染。
这意味着如果您想添加任何过渡效果(例如淡入淡出或滑动),您可能会将它们添加到视图的渲染方法中。
在视图渲染方法中添加一些效果。
这是可行的,对模型的任何更改都会导致视图渲染,我们将看到向下滑动的效果。但这只是因为视图已经附加到 DOM 中了!!!问题是,我们注意到页面加载时不会发生幻灯片效果。因此,作为补丁,我们在创建视图并将其附加到 DOM 的位置复制效果。
页面加载时效果没有发生的原因是,在我们将视图元素附加到 DOM 之前,效果已经发生了。
但为什么要重复这个效果,对我来说稍微改变一下视图是有意义的。
创建视图并将其附加到 DOM
In my opinion the problem is with having the view's render method return the view.
Your view probably looks something like this:
Then somewhere you have a method that creates the view and attaches it to the DOM.
The problem is that render() must be called to gain access to the view's element...
Think about this, when a change is made on the model the view is going to render again.
This means if you want to add any transition effects such as fading or sliding your likely going to add them in the view's render method.
Add some effects into the views render method.
This works, any change to the model will cause the view to render and we will see the slide down effect. But only because the view has already been appended to the DOM!!! THE PROBLEM, we notice that the slideDown effect does not happen on page load. So, as a patch, we duplicate the effect in the place where we are creating the view and appending it to the DOM.
The reason why the effect does not occur on page load is because the effect has already happened before we are appending the view's element to the DOM.
But why duplicate the effect, it makes sense to me to change the view a little.
Create the view and append it to the DOM
这似乎也有效
This also appears to work