简体   繁体   English

jQuery-从滑块移除下一个,上一个按钮

[英]jQuery - Remove Next, Prev Buttons from Slider

I tried searching for this, but I had trouble finding something directly related. 我尝试搜索此内容,但找不到与之直接相关的内容。 I am new to jQuery/Javascript so any help would be greatly appreciated! 我是jQuery / Java的新手,所以将不胜感激! Thank you! 谢谢!

I have a custom slider functionally working with 3 slides in it, and I am using jQuery to toggle back and forth between the slides. 我有一个自定义滑块,在功能上可以处理3张幻灯片,并且我正在使用jQuery在幻灯片之间来回切换。 Each slide is 1040px wide. 每张幻灯片的宽度均为1040px。 Each slide is relatively positioned, and is floating left. 每个幻灯片都相对放置,并且向左浮动。

I would like to hide my "button-right" when my slider is at the beginning (so you don't scroll to an empty area), and hide my "button-left" when my slider is at the end (again, so you don't scroll into an empty area). 我想在滑块开始时隐藏我的“向右按钮”(这样您就不会滚动到空白区域),而在滑块结束时隐藏我的“向左按钮”(同样,所以您不会滚动到空白区域)。

What logic can I use to do this? 我可以使用什么逻辑来做到这一点?

$(function(){
$(".button-right").click(function() {
    $(".portfolioSection").animate({left: "-=1040" }, "slow");
}); });

$(function(){
$(".button-left").click(function() {
    $(".portfolioSection").animate({left: "+=1040" }, "slow");
}); });

Here is the HTML 这是HTML

<div class="portfolioImg" style="background-image: url(images/featured-flushed.jpg);">
    <div class="portfolioImgOver">
        <div class="button-right">Next</div>
        <div class="button-left">Back</div>
        <div class="portfolioSection">
            <div class="finley"></div>
            <div class="portfolioContent">
                <h2>Flushed</h2><br/><br/>Flushed was a project planned for release on mobile platforms.<br /><br />My responsibilities for Flushed included: establishing a visual direction for the game, creating stylized 3D models, and developing technical game art, including textures, user interfaces and sprite sheets.<br /><br />I also worked with another artist to guide and assist with creating concept art, story mechanics and level designs.<br /><br /><span style="font-size:10px; color:#aaa;">Flushed is owned by Applied Studios, LLC.</span>
            </div>
        </div>

        <div class="portfolioSection">
            <div class="portfolioContent">
                <h2>WHOA! Another div</h2><br/><br/>Here is some crazy cool stuff that I bet you thought you would never see.
            </div>
        </div>

        <div class="portfolioSection">
            <div class="portfolioContent">
                <h2>WHOA! Another div</h2><br/><br/>Here is some crazy cool stuff that I bet you thought you would never see. 
            </div>
        </div>

        <div class="clear"></div>

    </div>
</div>

Here is the CSS 这是CSS

<style>.portfolioImg {width:1040px; height:600px; background-color:#efefef; margin-bottom:150px; z-index:1; overflow:hidden;}.portfolioImgOver{width:2080px; height:600px; background: rgba(25,25,25,.94);margin-bottom:150px; display:none; z-index:2; left:0px; position:relative;}.portfolioSection{width:1040px; height:600px; position:relative; float:left;}.portfolioContent{width:300px; color:#dedede; padding:40px; float:left; line-height:22px;}.portfolioContent a{color:#dedede; border-bottom:dotted 1px #888; padding-bottom:1px; text-decoration:none;}.button-right {width:60px; background:#333; color:#fff; padding:10px; position:absolute; z-index:3; right:1040px; top:300px; cursor:pointer; transition: all 0.6s ease 0s; -webkit-transition: all 0.6s ease 0s;}.button-right:hover {background:#777; transition: all 0.6s ease 0s; -webkit-transition: all 0.6s ease 0s;}.button-left {width:60px; background:#333; color:#fff; padding:10px; position:absolute; z-index:3; left:0px; top:300px; cursor:pointer; transition: all 0.6s ease 0s; -webkit-transition: all 0.6s ease 0s;}.button-left:hover {background:#777; transition: all 0.6s ease 0s; -webkit-transition: all 0.6s ease 0s;}</style>

Here is a link to the page: 这是页面的链接:

http://alanvitek.com/dev http://alanvitek.com/dev

Try to set a variable for your slides (may be in an array), then check if it is the first one, hide the left button. 尝试为幻灯片设置一个变量(可能在数组中),然后检查它是否为第一个变量,隐藏左按钮。 if it is the last, hide the right button. 如果是最后一个,则隐藏右键。

$('.button-left').hide()

Try 尝试

jQuery(function($){
    var sec = $('.portfolioSection'), secwidth = sec.width(), unit = 1040;

    $(".button-right").click(function() {
        var left = sec.css('left');
        left = Math.abs(parseInt(left.substring(0, left.length - 2)))
        if(left + unit >= secwidth){
            $(this).hide()
        }

        sec.animate({left: "-=" + unit }, "slow");
        $(".button-left").show();
    });


    $(".button-left").click(function() {
        var left = sec.css('left');
        if(left == '-' + unit + 'px'){
            $(this).hide()
        }
        sec.animate({left: "+=" + unit }, "slow");
        $(".button-right").show();
    });
})

Demo: Fiddle 演示: 小提琴

Set an variable with the status. 设置状态变量。 1 is the first slide, 2 the second and so on. 1是第一张幻灯片,2是第二张幻灯片,依此类推。 On every key press add 1 or subtract 1. After that, you can do following: 在每个键上按加1或减1。之后,您可以执行以下操作:

if(variable == 1)$('.button-left').hide()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM