动画不能与不同的HTML标记一起工作
Animation not working with different HTML markup
我有一个正在工作的jQueryMobile HTML标记,但是当我试图使它与我将使用的不同HTML标记一起工作时,动画不工作,我试图使用不同的jQuery方法&函数使它工作。
工作示例http://jsfiddle.net/yVtVe/22/
需要实现相同的http://jsfiddle.net/yVtVE/25/
childrenvar stopAnim = false;
function animateTitle(scrollingWidth, initialOffset,elem){
if(!stopAnim ){
var $a = elem;
$a.animate({left: (($a.offset().left == (scrollingWidth + initialOffset ))?-initialOffset:("-="+scrollingWidth))},
{
duration: 5000,
easing: 'swing',
complete: function(){
if($a.offset().left < 0){
$(this).css("left", scrollingWidth);
}
animateTitle(scrollingWidth);
}
});
}
}
$('#swrapper ul li').hover(
function () {
var scrollingWidth = $(this).children('div.list-heading').children('h2').width();
alert(scrollingWidth);
var elem = $(this).children('div.list-heading').children('h2');
if(scrollingWidth > 330){
scrollingWidth = scrollingWidth + 10;
var initialOffset = $(this).children('div.list-heading').children('h2').offset().left;
stopAnim = false;
animateTitle(scrollingWidth, initialOffset,elem);
}
},
function () {
stopAnim = true;
$(this).children('div.list-heading').children('h2').stop(true, true).css("left", "0");
}
);
你的javascript有一个错误:
childrenvar stopAnim = false;
应为
childrenvar_stopAnim = false;
我已经删除了js错误:http://jsfiddle.net/yVtVE/28/
这是小提琴的最终工作版本:
http://jsfiddle.net/yVtVE/54/我将在这里发布工作js代码:
var childrenvar, stopAnim = false;
function animateTitle(scrollingWidth, initialOffset, elem) {
if (!stopAnim) {
var $a = elem;
$a.animate({
left: (($a.offset().left == (scrollingWidth + initialOffset)) ? -initialOffset : ("-=" + scrollingWidth))
}, {
duration: 5000,
easing: 'swing',
complete: function () {
if ($a.offset().left < 0) {
$(this).css("left", scrollingWidth);
}
animateTitle(scrollingWidth);
}
});
}
}
$('#swrapper ul li').hover(
function () {
var scrollingWidth = $(this).select('div.list-heading').children().select('h2').width();
var elem = $(this).select('div.list-heading').children().select('h2');
if (scrollingWidth > 330) {
scrollingWidth = scrollingWidth + 10;
var offset = $(this).select('div.list-heading').children().select('h2').offset();
if (offset !== null) {
var initialOffset = offset.left;
stopAnim = false;
animateTitle(scrollingWidth, initialOffset, elem);
}
}
},
function () {
stopAnim = true;
$(this).select('div.list-heading').children().select('h2').stop(true, true).css("left", "0");
});
相关文章:
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- document.title函数可以't设置它与php一起工作
- "此网站似乎使用滚动链接定位效果.这可能不能很好地与异步平移一起工作;
- 非常简单的js测试;Don’不要和Minko一起工作
- 无法使我的文本参数与我的查询一起工作
- 为什么Angularjs验证don't与输入[type=“number”]一起工作
- 无法使vash 0.8.0与express 4.12.3一起工作
- 如何使Angular JS控制器与指令一起工作
- 无法使autocompletion与bootstrap和php代码点火器一起工作
- 注入的元素和jQuery脚本.如何让他们一起工作
- 两个独立工作的javascript函数,但不能一起工作
- 角度和砖石一起工作
- Node http-proxy-middleware 不能与本地服务器一起工作
- jQuery脚本不想一起工作
- page.js使examples/hash与hashbang:true一起工作
- javascript使jquery倒计时与UTC时间一起工作
- jQuery.not()选择器无法与类一起工作
- Rails3-可排序列表不能与wysihtml5一起工作
- 替换匹配函数给出了未定义的错误,但它与替换一起工作
- 按钮上的数据加载消息无法与ajax调用一起工作