javascript - 设置 maxzoom 和 minzoom 属性
问题描述
我想设置 maxzoom 和 minzoom 属性 - 因为当我单击 zoomin 按钮时,文本变得越来越大,所以我想在我的 jquery 代码中设置 maxzoom 和 minzoom 属性。
我的 html 代码和 jquery 代码如下。
重置按钮效果很好,但是当我继续单击放大和缩小按钮时,文本变得越来越大,而在 zoomout 属性中,文本变得越来越小......所以我想设置 maxzoom 和 minzoom 属性。
<button class="zoomIn">Zoom In</button>
<button class="zoomOff">Reset</button>
<button class="zoomOut">Zoom Out</button>enter code here
<script>
$('.open-book').css({
// 'position' : 'absolute',
'top' : '0px',
'left' : '0px',
'height' : $('.outboard').height(),
'width' : $('.outboard').width()
});
var currZoom = 1;
$(".zoomIn").click(function(){
currZoom+=0.1;
$('.open-book').css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
});
$(".zoomOff").click(function(){
currZoom=1;
$(".open-book").css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
});
$(".zoomOut").click(function(){
currZoom-=0.1;
$('.open-book').css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
});
</script>
解决方案
您必须定义minZoom
和maxZoom
值并与 进行比较currZoom
。通过包装在if
条件和更改元素中比较值CSS
。
试试这个代码。
<button class="zoomIn">Zoom In</button>
<button class="zoomOff">Reset</button>
<button class="zoomOut">Zoom Out</button>enter code here
<script>
$('.open-book').css({
// 'position' : 'absolute',
'top' : '0px',
'left' : '0px',
'height' : $('.outboard').height(),
'width' : $('.outboard').width()
});
var currZoom = 1;
var minZoom = 1;
var maxZoom = 2;
$(".zoomIn").click(function(){
if(maxZoom >= currZoom){
currZoom+=0.1;
$('.open-book').css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
}
});
$(".zoomOff").click(function(){
currZoom=1;
$(".open-book").css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
});
$(".zoomOut").click(function(){
if(minZoom <= currZoom){
currZoom-=0.1;
$('.open-book').css({
// 'position' : 'absolute',
// 'top' : '45px',
// 'left' : '20px',
// 'height' : $(window).height()-65,
// 'width' : $(window).width()-40,
'zoom' : currZoom
});
}
});
</script>
推荐阅读
- wordpress - 验证 Wordpress 帖子 URL 是否真实?
- python - 查询多对多关系Django
- c# - 分配给 DatePicker 的变量不返回值
- git - 在同一个存储库上触发多个管道
- snowflake-cloud-data-platform - 雪花,如何删除展平记录?
- android - 如何通过 adb 命令更改刷新率
- arrays - MongoDB查询文档数组
- python - 同步 Azure Functions 执行的工作
- symfony - Prestashop。如何允许匿名用户访问自定义 symfony 控制器?
- python - 在python中将多个字符串转换为数据框