我的JavaScript代码是这样的,只有在选中复选框后才能运行此功能,并且在选中复选框时不应运行此功能。
<script type="text/javascript">
$(document).ready(function zoom() {
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
});
答案 0 :(得分:1)
假设您已准备好文档的id="chkboxID"
复选框,您可以使用.is
方法,但这只会在页面加载时检查
$(function(){
if($("#chkboxID").is(":checked")){
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
}
});
<强>更新强>
更新的代码会将更改事件处理程序附加到每个 页面上的复选框,如果你想听听的变化 特定复选框相应地更改选择器
$(":checkbox").change(function(){
if($(this).is(":checked"))
{
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
}
});
答案 1 :(得分:1)
function zoom() {
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
}
$(function () {
$( < your checkbox selector > ).change(function () {
if ($(this).prop('checked')) {
zoom();
}
}).change();
});
答案 2 :(得分:0)
var checkbox_value = 1; //Its checked on
if(checkbox_value){
$(document).ready(function zoom() {
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
});
}
答案 3 :(得分:0)
<input class="mycheck" type="checkbox"/>
JS:
$(".mycheck").change(function(){
if(this.checked){ zoom(); }
})
function zoom() {
$('.ThumbaGallery').Thumba({
effectThumba: 'easeOutBack',
effectDuration: 450,
keyNav: true,
mouseNav: true,
coeffZoom: 2.5,
speedOpenLightBox: 100,
legendPadding: 5,
legendOpacity: 0.8
});
}