简体   繁体   English

带有CSS变换的jQuery Sparklines

[英]jQuery Sparklines with CSS Transform

I'm using jQuery Sparklines on an html page which is scaled using transform: scale . 我在html页面上使用jQuery Sparklines ,该页面使用transform: scale Unfortunately, this causes the tooltip generated by jQuery Sparklines to be displayed in the wrong spot. 不幸的是,这导致jQuery Sparklines生成的工具提示显示在错误的位置。 For example, the following code... 例如,以下代码...

<style>
body {
  transform: scale(0.7); 
  transform-origin: 0 0;
}
</style>

<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="jquery.sparkline.min.js"></script>

<script type="text/javascript">
  $(function() {
    var myvalues = [10,8,5,7,4,4,10];
    $('#line').sparkline(myvalues, {
        type: 'line'
    });
});
</script>

<div> random text random text random text random text random text random text <span id="line"></span>  </div>

... results in this: ...导致:

在此处输入图片说明

Is there some way to fix this behaviour? 有什么办法可以解决此问题?

Rename your style from "body" to "div" it will work. 将您的样式从“ body”重命名为“ div”即可。

As the transfer:scale is affecting the whole page, we need to specify to the specific div tag. 由于transfer:scale影响整个页面,因此我们需要指定特定的div标签。

The Problem is you have specified the transform to total body so only its getting affected give the transform css to particular div or use :not selector in css 问题是您已将变换指定为整体,因此只有其受影响才会将变换CSS赋予特定的div或在CSS中使用:not选择器

Here the fiddle Link: https://jsfiddle.net/hahkarthick/3v0s0xvm/ 这里的小提琴链接: https : //jsfiddle.net/hahkarthick/3v0s0xvm/

  $(function() { var myvalues = [10,8,5,7,4,4,10]; $('#line').sparkline(myvalues, { type: 'line' }); }); 
 div:not(span){ transform: scale(0.7); transform-origin: 0 0; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-sparklines/2.1.2/jquery.sparkline.js"></script> <div> random text random random text random text <span id="line"></span> </div> 

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

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