The ultimate solution for image distortion in the bootstrap Carousel (Carousel) plugin-using jqthumb.js

Source: Internet
Author: User
Tags bootstrap carousel

I used the bootstrap carousel (carousel) plugin to display the pictures in the article on the top of the homepage. I in the program automatically grabbed the first picture of the article as the Carousel control to display the picture, because the article size of the picture, and the size of the carousel is basically fixed, so when the picture appears distorted. In the online find a lot of ways also did not solve (process twists and turns, no longer repeat), until found this jquery zoom plugin- Jqthumb.js. below to see how it can be used and how to use it to control the size of the picture in the carousel control, and to be able to do not deform, you can display the main part of the picture (similar to the picture of the circle of Friends of the image mix effect-do not know whether you have noticed, in the circle of friends regardless of the ratio of the Can always be perfectly arranged without distortion. First, let's look at Bootstrap's Carousel HTML code:

<div id= "Carousel-example-generic" class= "Carousel Slide" data-ride= "Carousel" >
<!--Wrapper for slides--
<div class= "Carousel-inner" role= "ListBox" >
<div class= "Item Active" >
<a href= "contains picture an article path" >
</a>
<div class= "Carousel-caption" >

<a style= "color:white;" href= "contains a picture of an article path" > Picture title </a>
</div>

</div>
<div class= "Item" >
<a href= "contains picture two article path" >

</a>
<div class= "Carousel-caption" >

<a style= "color:white;" href= "contains picture two article path" > picture two title </a>
</div>
</div>
<div class= "Item" >
<a href= "contains picture three article path" >

</a>
<div class= "Carousel-caption" >

<a style= "color:white;" href= "contains picture three article path" > picture three title </a>
</div>
</div>
</div>

As you can see from the above code, each image (IMG) invokes a function drawimage at the time of loading (onload), In this function we can call the Jqthumb.js method to control the size of the image, note that the function must be added to the above HTML code, or the first time the load control picture size will fail (because the page load timing reason), the function code is as follows:

<!--Import Plugins--
<script type= "Text/javascript" src= "/static/plugins/thumb/js/jqthumb.js" ></script>
<script>
function DrawImage (hotimg)
{
$ (hotimg). Jqthumb ({
ClassName: ' Jqthumb ',
Width: ' 100% ',
Height: ' 300px ',
Position: {y: ' 50% ', x: ' 50% '},
Zoom: ' 1 ',
Method: ' Auto ',
});
}
</script>

In this function we call the Jqthumb method to define a thumbnail of the original image with a width and a carousel height of 300px, which is generated from the center of the image (note the setting of its position property) so that the image's main contents can be displayed even if the size of the picture changes. , and the picture ratio can remain the same.

Above is all the content, hope to be helpful to everyone, reproduced please indicate the source for the top of the network

The ultimate solution for picture warping in the bootstrap Carousel (Carousel) Plugin-using jqthumb.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.