Блог про верстку и CSS. Примеры html кода и интересные приемы.
Закругленные уголки у картинок с помощью jQuery
Недавно была необходимость сделать круглые уголки у картинки... повозился... отказался от идеи не найдя хорошего решения...
Случайно нашел оч. хороший способ...
Хочется вот такой красоты после применения border-radius и box-shadow:

А получаем:

Есть небольшой трюк для фикса:
<span class="rounded-img" style="background: url(img/thumb1.jpg) no-repeat center center; width: 70px; height: 70px;"> <img src="img/thumb1.jpg" style="opacity: 0;" /> </span>
Вокруг картинки добавляем и на него вешаем background саму картинку, а оригинал скрываем: opacity: 0.
Для упрощения стоит воспользоваться jQuery:
<img src="img/thumb1.jpg" class="rounded-img" /> <img src="img/thumb2.gif" class="rounded-img2" />
Стили:
/* rounded image styles */ .rounded-img { display: inline-block; border: solid 1px #000; overflow: hidden; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, .4); -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, .4); box-shadow: 0 1px 3px rgba(0, 0, 0, .4); } .rounded-img2 { display: inline-block; -webkit-border-radius: 10px; -moz-border-radius: 10px; border-radius: 10px; -webkit-box-shadow: inset 0 1px 5px rgba(0, 0, 0, .5), 0 1px 0 rgba(255, 255, 255, .9), 0 -1px 0 rgba(0, 0, 0, .6); -moz-box-shadow: inset 0 1px 5px rgba(0, 0, 0, .5), 0 1px 0 rgba(255, 255, 255, .9), 0 -1px 0 rgba(0, 0, 0, .6); box-shadow: inset 0 1px 5px rgba(0, 0, 0, .5), 0 1px 0 rgba(255, 255, 255, .9), 0 -1px 0 rgba(0, 0, 0, .6); }
Javascript:
<script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".rounded-img, .rounded-img2").load(function() { $(this).wrap(function(){ return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />'; }); $(this).css("opacity","0"); }); }); </script>
Результат:

Источник: http://www.webdesignerwall.com/tutorials/css3-rounded-image-with-jquery/
| Print article | This entry was posted by pulev on 12.07.2010 at 15:24, and is filed under css, hints, js. Follow any responses to this post through RSS 2.0. Вы можете оставить комментарий или трэкбэк с вашего сайта. |