具有音量控制器功能的网页单选按钮



我有这个使用jquery的脚本:

$(document).ready(function() {
    $('.fotky,.video,.diskusia,.onas,.zbrane,.akcie,.tabroz,.tabburk,.tabhil,.tablest').append('<span class="hover"></span>').each(function () {
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function () {
            $span.stop().fadeTo(1000, 1);
        }, function () {
    $span.stop().fadeTo(1000, 0);
        });
    });
});

我有这个CSS代码:

.fotky {
clear: both;
position:relative;
display:block;
height: 56px;
width: 126px;
background:url(images/Fotky.png) no-repeat;
background-position: top;
cursor: pointer;
}
.fotky span.hover {
position: relative;
display: block;
height: 56px;
width: 126px;
background: url(images/Fotky.png) no-repeat;
background-position: bottom;
}

这是我的网站我的测试网站我如何使按钮作为单选按钮工作,这样就会有第三部分的图像,它将在点击后显示,并在点击另一个按钮后隐藏。当点击的部分显示出来时,悬停功能不应该在这个按钮上工作。有办法做到这一点吗?

不确定我是否理解正确,但我想这方面的内容应该会有所帮助。

css:

.hover{display:none;}

脚本:

$('.a, .b, .c').each(function() {
    var $this = $(this);
    $span = $('<span class="hover"/>');
    $span.hover(function(){$(this).fadeIn()}, function(){ $(this).fadeOut()});
    $this.filter('a').click(function(e) {
        // do something with the click.
        e.stopPropagation(); e.preventDefault();
        $(this).hover = null; // you can save hover function in a var if you want to use it later.
    });
    $this.filter('b').click(function(e) {
        // do something with the click.
        e.stopPropagation(); e.preventDefault();
        $(this).hover = null; // you can save hover function in a var if you want to use it later.
    });
    $this.filter('c').click(function(e) {
        // do something with the click.
        e.stopPropagation(); e.preventDefault();
        $(this).hover = null; // you can save hover function in a var if you want to use it later.
    });
});

所以现在我有了这个:

脚本:

$(document).ready(function() {
    $(".fg-button")
    .hover(
        function(){ 
            $(this).addClass("ui-state-hover");
        },
        function(){
            $(this).removeClass("ui-state-hover"); 
        }
    )
    .mousedown(function(){
            $(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
            if( $(this).is('.ui-state-active') ){ $(this).removeClass("ui-state-active"); }
            else { $(this).addClass("ui-state-active"); }   
    })
    .mouseup(function(){
        if(! $(this).is('.fg-buttonset-single .fg-button') ){
            $(this).removeClass("ui-state-active");
        }
    });
});

CSS:

.fg-button {height: 56px; width: 126px; border: 0px; outline: 0px; cursor:pointer; position: relative; display:block;}
.ui-state-default { clear: both; background: url(images/Fotky.png) no-repeat; background-position: top;}
.ui-state-hover{background: url(images/Fotky.png) no-repeat; background-position: bottom;}
.ui-state-active {background: url(images/Fotky.png) no-repeat; background-position: center;}

HTML:

<div class="fg-buttonset fg-buttonset-single">
<button class="fg-button ui-state-default"></button>
<button class="fg-button ui-state-default"></button>
<button class="fg-button ui-state-default"></button>
<button class="fg-button ui-state-default"></button>

这是我需要的工作,但没有fadeTo功能。我如何在那里实现它,使它像本页顶部的示例一样工作?我试了几次,但没有成功。

以下是测试的工作原理http://airsoftbanda.tym.sk/css/test.php

以下是fadeTo的工作原理http://airsoftbanda.tym.sk/css/index.php

最后,这是我的最终解决方案,它可以根据我的需要工作。。。

脚本:

$(document).ready(function() {
    $('.fotky,.video,.diskusia,.onas,.zbrane,.akcie,.tabroz,.tabburk,.tabhil,.tablest').append('<span class="hover"></span>').each(function () {
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function () {
            $span.stop().fadeTo(1000, 1);
        }, function () {
    $span.stop().fadeTo(1000, 0);
        });
$(".fotky").mousedown(function(){
$(this).parents('#tlacidlo:first').find(".fotkyk,.videok,.diskusiak,.onask,.zbranek,.akciek").removeClass("fotkyk videok diskusiak onask zbranek akciek");
  $(this).addClass("fotkyk"); 
$span.stop().fadeTo(1000, 0);
end;    
    });
    $(".video").mousedown(function(){
    $(this).parents('#tlacidlo:first').find(".fotkyk,.videok,.diskusiak,.onask,.zbranek,.akciek").removeClass("fotkyk videok diskusiak onask zbranek akciek");
$(this).addClass("videok");
$span.stop().fadeTo(1000, 0);   
    });

CSS:

#tlacidlo {
height: 400px;
width: 126px;
float: left;
margin-left: 20px;
margin-top: 20px;
}
.fotky {
clear: both;
position:relative;
display:block;
height: 56px;
width: 126px;
background:url(images/Fotky.png) no-repeat;
background-position: top;
cursor: pointer;
}
.fotky span.hover {
position: relative;
display: block;
height: 56px;
width: 126px;
background: url(images/Fotky.png) no-repeat;
background-position: bottom;
    }
.fotkyk {
position: relative;
display: block;
height: 56px;
width: 126px;
background: url(images/Fotky.png) no-repeat;
background-position: center;
}

HTML:

<div id="tlacidlo">
<a href="#" class="fotky"></a>
<a href="#" class="video"></a>
<a href="#" class="diskusia"></a>
<a href="#" class="onas"></a>
<a href="#" class="zbrane"></a>
<a href="#" class="akcie"></a>
</div>

当然,它只是代码的一部分,因为它在脚本和css上几乎是重复的。

最新更新