【发布时间】:2015-06-12 20:42:58
【问题描述】:
我正在制作一个 jQuery 滑块,但我似乎无法让滑块真正滑动。箭头正在工作,因为正在添加我添加的类,但它不会导致图像滑过。图像被绘制到滑块并正确显示,图像从右侧的滑块上脱落。我的代码没有滑动有什么问题?非常感谢任何帮助 这是我的 XSL(出于某种原因,必须去掉前两个 xsl 标签才能显示。如果需要,请告诉我):
<xsl:param name="StyleNode" />
<xsl:if test="$Node/RelatedProducts_Expanded != ''">
<div class="relatedProducts siteBounds">
<div class="wrapper">
<h5>Related Products</h5>
<div class="slider sliderRelatedProducts">
<div class="leftarrow" >
<i class="fa fa-angle-double-left"> </i>
</div>
<div class="rightarrow" >
<i class="fa fa-angle-double-right"> </i>
</div>
<div class="clipper">
<ul>
<xsl:for-each select="$Node/RelatedProducts_Expanded/Option">
<li>
<div class="productWrapper">
<xsl:if test="./ImageFile != ''">
<a href="{./@Value}" class="image">
<img>
<xsl:attribute name="src">
<xsl:value-of select="./ImageFile" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="./DisplayName"/>
</xsl:attribute>
</img>
</a>
</xsl:if>
<h4>
<a href="{./@Value}">
<xsl:value-of select="./DisplayName" disable-output-escaping="yes" />
</a>
</h4>
<p class="teaser">
<xsl:value-of select="./ShortDescription"/>
</p>
<p class="linkText">
<a href="{./@Value}">
Read more
</a>
</p>
</div>
</li>
</xsl:for-each>
</ul>
</div>
</div>
</div>
</div>
这是我的 jQuery 代码:
function slider(wrapper){
$(wrapper + ' ul').each(function () {
// this part unrelated to resize
var numItems = $(wrapper + ' li').length; // number of items in slider
var imgw = $(wrapper + ' li').width(); // width of image in li
var ml = parseInt($(wrapper + ' li:first-child').css('marginLeft').replace('px','')); //left margin
var mr = parseInt($(wrapper + ' li:first-child').css('marginRight').replace('px','')); //right margin
var m = (ml+mr); //total margin
var itemWidth = (imgw+m); // img width + margin
var ulWidth = (itemWidth*numItems); // width for ul
$(wrapper + ' ul').width(ulWidth); // apply ul width
var $list = $(wrapper + ' .clipper ul');
var $prev = $(wrapper + ' .leftarrow').css({ display:'block'}); // previous
var $next = $(wrapper + ' .rightarrow').css({ display:'block'}); // next
var $clip = $(wrapper + ' .clipper');
$prev.addClass("disabled");
if ($(this).width() < $clip.width()){
$next.addClass("disabled");
$prev.addClass("disabled");
} else {
$next.click(function () {
var pos = $list.position();
var scroll = itemWidth * -1;
var scrollStop = ((numItems * itemWidth) - $clip.width()) * -1;
if ((pos.left > scrollStop) && (pos.left + scroll > scrollStop))
$list.animate({ left: "+=" + scroll + "px" }, "normal");
else if (pos.left + scroll <= scrollStop) {
$list.animate({ left: scrollStop + "px" }, "normal");
$next.addClass("disabled");
$prev.removeClass("disabled");
}
$prev.removeClass("disabled");
});
$prev.click(function () {
var pos = $list.position();
var scroll = itemWidth;
var scrollStop = 0;
if ((pos.left < scrollStop) && (pos.left + scroll < scrollStop))
$list.animate({ left: "+=" + scroll + "px" }, "normal");
else if (pos.left + scroll >= scrollStop) {
$list.animate({ left: scrollStop + "px" }, "normal");
$prev.addClass("disabled");
$next.removeClass("disabled");
}
$next.removeClass("disabled");
});
}
});
}
【问题讨论】:
标签: javascript jquery xml xslt slider