我有滑块和嵌套在这个滑块中的一些div。所有这些div都按顺序出现。我的一些div有头衔。当这些div出现时,我想得到警报。我无法弥补逻辑!这是我的代码:
//resize ul to float left li elements
var outerWith = $(".slider_panel").outerWidth();
var len= $(".slider_panel").length * outerWith;
$(".slider_content ul").css({width: len});
//left arrow --- slider moves left
$(".left_arrow").click(function() {
$(".slider_content").animate({scrollLeft:'-=' + outerWith},500);
});
//right arrow -- slider moves right
$(".right_arrow").click(function() {
$(".slider_content").animate({scrollLeft:'+=' + outerWith},500);
});
// add li elements to slider context as much as slider panel which has title attribute.
$(".slider_panel[title]").each(function(index) {
var content = $(this).attr('title');
$(".slider_contex ul").append('<li>'+content+'</li>');
});
//click slider li elements and go equivelent slider page
$(".slider_contex ul li").click(function() {
$(this).addClass("current").siblings().removeClass("current");
var thisText = $(this).text(); //console.log(thisText);
var minus = outerWith / 2;
//console.log("minus= " + minus);
var panelAttr = $(".slider_panel[title="+thisText+"]");
var panelTitle = panelAttr.position().left - minus; //console.log(panelTitle);
$(".slider_content").animate({scrollLeft: '+=' + panelTitle},500);
});
问题是当我的带有title属性的div出现时,我想要提醒。 我也创建了一个如下所示的函数,但它不起作用:
function detect_position()
{
var sliderContentOffset = $(".slider_content").position().left; console.log("sliderContentOffset = " + sliderContentOffset);
var optOffset = $(".slider_panel[title='uc']").position().left; console.log("optOffset = " + optOffset);
var width=$(".slider_panel[title='uc']").width(); console.log("width = " + width);
var sum = optOffset + width; console.log("sum = " + sum);
if(sliderContentOffset >=optOffset && sliderContentOffset<= optOffset + width )
console.log("dropped");
}