我有滑块和一些嵌套在此滑块中的 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);
});
问题是当我的带有标题属性的 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");
}