[英]Radio buttons for web page with fadeto function
我有这个脚本使用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上几乎重复相同的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.