简体   繁体   English

JQuery图像滑块有图像宽度和高度问题

[英]JQuery image slider having issue with image width & height

I am using image slider specified at: here 我正在使用指定的图像滑块: here

My images are of different sizes and I want to set the width and height of the image using following code: 我的图像大小不同,我想使用以下代码设置图像的宽度和高度:

<img src='77.png' width="20px" height="20px" />

But this doesnt work. 但这不起作用。

I am preety new to javascript, any help will be greatly approciated! 我是javascript的新手,任何帮助都将大大适应!

I really don't think this code can handle it (perhaps with a very serious overhaul of the javascript). 我真的不认为这段代码可以处理它(也许是对javascript进行非常严肃的改造)。 I set up a fiddle here: http://jsfiddle.net/JLjCP/9/ and in examining what it is doing, it simply does not care what size the image itself is nor does it care if you have resized the image explicitly through the width and height properties. 我在这里设置了一个小提琴: http//jsfiddle.net/JLjCP/9/并且在检查它正在做什么时,它根本不关心图像本身的大小,也不关心如果你通过显式调整图像大小widthheight属性。 It is only taking the referenced image file and using it as a repositioned background image for the split components which are purely sized by the width and height of the display and the number of sections you tell it to do it in. 它只接受引用的图像文件,并将其用作拆分组件的重新定位背景图像,这些组件的大小完全按显示器的宽度和高度以及您指示它执行的部分数量。

So the short answer is this code will not do what you want it to do. 所以简短的回答是这段代码不会做你想做的事情。

put this in your css : 把它放在你的CSS中:

    .cs-coin-slider
    {
    /*i think the class name is depend on what you set*/ 
        -o-background-size: 20px 20px;
        -webkit-background-size: 20px 20px;
        -khtml-background-size: 20px 20px;
        -moz-background-size: 20px 20px;
        background-size: 20px 20px;
    }

if you insist to use this coin-slider, no matter you set the size in html or set the css width+height of the image, it wont resized because this plugin treats the image as background..and that css3 background resize that is the only way that save you :) 如果你坚持使用这个硬币滑块,无论你在html中设置大小或设置图像的css宽度+高度,它都不会调整大小,因为这个插件将图像视为背景..而且css3背景调整大小是只有这样才能救你:)

The documentation on that page says that you can pass size options to the constructor: 该页面上的文档说明您可以将大小选项传递给构造函数:

$('#coin-slider').coinslider({ width: 20, height: 20 });

If you have different sized images in the same slideshow and you want to change the slider's size dynamically, it might not be possible. 如果您在同一幻灯片中有不同大小的图像,并且想要动态更改滑块的大小,则可能无法实现。 Use same sized images or tweak the CSS so that you get black bars around smaller images or something to that effect. 使用相同大小的图像或调整CSS,以便在较小的图像周围获得黑条或类似的效果。

Please post your complete HTML/JS source code, the image size shouldn't matter as long as they are the same height/width as the container of the slideshow. 请发布完整的HTML / JS源代码,图像大小无关紧要,只要它们与幻灯片的容器具有相同的高度/宽度即可。 Chances are you are possibly calling the plugin in the wrong way in your JS. 您可能在JS中以错误的方式调用插件。

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

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