简体   繁体   English

jQueryUI滑块问题在CSS规模上

[英]jQueryUI slider issue on css scale

I have some issue with jQuery slider when I scale it with css transform: scale(x) 使用CSS transform: scale(x)时,jQuery滑块出现问题transform: scale(x)

I understand that calculations of pixels on slider drag are not correct while it's scaled, but is there any solution? 我知道滑块缩放时像素拖动的像素计算不正确,但是有什么解决方案吗?

Here is the example of my issue: 这是我的问题的示例:

 $('.slider-1').slider(); $('.slider-2').slider(); 
 .wrapper-1, .wrapper-2 { padding: 25px; width: 500px; } .slider-2 { marggin-top: 50px; transform: scale(0.6); transform-origin: 0; } 
 <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="wrapper-1"> <p>Slider normal</p> <div class="slider-1"></div> </div> <div class="wrapper-2"> <p>Slider transformed (scaled)</p> <div class="slider-2"></div> </div> 

It won't work cause the position changes as a percentage. 由于排名以百分比变化,因此无法正常工作。 So its moving correctly but appears to be wrong cause its not at the position of mouse cursor. 因此其正确移动但似乎有误,导致其不在鼠标光标的位置。
For the right result you can set width height and top of slider , handle manually 为了获得正确的结果,您可以设置width height和滑块top ,手动处理

 $('.slider-1').slider(); $('.slider-2').slider(); 
 .wrapper-1, .wrapper-2 { padding: 25px; width: 500px; } .slider-2 { margin-top: 50px; height: 5px !important; width: 100px; } .slider-2 span { transform: scale(0.6); top:-9px !important; } 
 <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="wrapper-1"> <p>Slider normal</p> <div class="slider-1"></div> </div> <div class="wrapper-2"> <p>Slider transformed (scaled)</p> <div class="slider-2"></div> </div> 

I don't think you can do that. 我认为您无法做到。 I also tried using scale and it gave the same behavior. 我也尝试使用scale ,它给出了相同的行为。 You could just change the width/height of the elements, it's easy to style. 您只需更改元素的宽度/高度,即可轻松设置样式。

 $('.slider-1').slider(); $('.slider-2').slider(); 
 .wrapper-1, .wrapper-2 { padding: 25px; width: 500px; } .slider-2.ui-slider-horizontal { marggin-top: 50px; transform-origin: 0; width: 60%; height: .5em; } .slider-2.ui-slider .ui-slider-handle { width: .8em; height: .8em; top: -0.2em; } 
 <link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <div class="wrapper-1"> <p>Slider normal</p> <div class="slider-1"></div> </div> <div class="wrapper-2"> <p>Slider transformed (scaled)</p> <div class="slider-2"></div> </div> 

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

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