What is the bestpractice, when I need to have SVG images with SVG hovers with fallbacks?
I mean SVG images with PNG fallbacks (normal, reaponsive 2x, 3x), and change them on hover to other SVG images with PNG fallbacks?
Is it better to use <img /> or <picture> + <source /> + <img /> tag with jQuery (or vanilla, but I already use jQuery), or to have it all in CSS as backgrounds? If jQuery, does it mean swapping srcsets? If CSS, how do I best include #2x and #3x image versions?
Also, how does the used method affect preloading of the hovers? It would surely be much better without blinking.
So far I have this, I need to change them on hover to 1hov.svg, 1hov.png, 1hov#2x.png, 1hov#3x.png
<a href="#">
<picture>
<source type="image/svg+xml" srcset="logos/1.svg">
<img src="logos/1.png" srcset="logos/1#2x.png 2x, logos/1#3x.png 3x" alt="logo">
</picture>
</a>
Here is a HTML + jQuery solution I found. It swaps the src and sourcesets to their hover alternatives. Includes the hovers preloading.
HTML
<a href="#" target="_blank">
<picture>
<source type="image/svg+xml" srcset="logos/1.svg" data-swap-srcset="logos/1hov.svg">
<img src="logos/1.png" data-swap-src="logos/1hov.png"
srcset="logos/1#2x.png 2x, logos/1#3x.png 3x" data-swap-srcset="logos/1hov#2x.png 2x, logos/1hov#3x.png 3x" alt="logo">
</picture>
</a>
jQuery
//preload hovers
$("source[data-swap-src]").each(function(){
$('<img/>')[0].src = $(this).attr("data-swap-src");
});
$("img[data-swap-src]").each(function(){
$('<img/>')[0].src = $(this).attr("data-swap-src");
$('<img/>')[0].srcset = $(this).attr("data-swap-srcset");
});
$("a").hover(function(){
var newone = $(this).find("img").attr("data-swap-src");
$(this).find("img").attr("data-swap-src", $(this).find("img").attr("src"));
$(this).find("img").attr("src", newone);
newone = $(this).find("img").attr("data-swap-srcset");
$(this).find("img").attr("data-swap-srcset", $(this).find("img").attr("srcset"));
$(this).find("img").attr("srcset", newone);
newone = $(this).find("source").attr("data-swap-srcset");
$(this).find("source").attr("data-swap-srcset", $(this).find("source").attr("srcset"));
$(this).find("source").attr("srcset", newone);
}
);
Related
How can I handle elements that are inside iframe which are again inside a shadow Dom using watir 7.2?
Something like this:
<div id="test">
#shadow-root (open)
<div id= "test1">
<iframe id= "iframe">
<input id = "text field">
Code-
shadow_host=#browser.div(id: 'test')
shadow_root=shadow_host.shadow_root
iframe= shadow_root.iframe(id: 'iframe').wai_until(&: present?)
iframe.text_fied(id: 'text field').set(params[:expiry] ||12345)
Please let me know what mistake I am doing?
I'm using Masonry and imageLoaded to load a wall of images : everytime an image is loaded, masonry layout is refreshed.
This works as intended, but problem is that most of the time, Masonry will move already loaded items to another position on refresh. Is there a way to force Masonry to keep already arranged items where they are ?
All the image have the same width (but not the same height).
HTML (with Bootstrap) :
<div class="container-fluid">
<div id="gallery">
<div class="item col-sm-3">
<img src="1.jpg" alt="">
</div>
<div class="item col-sm-3">
<img src="2.jpg" alt="">
</div>
<div class="item col-sm-3">
<img src="3.jpg" alt="">
</div>
<!--more items -->
</div>
</div>
JS :
// hide images
$('.item img').hide();
//init Masonry
var $grid = $('#gallery').masonry({
itemSelector: '.item',
transitionDuration: 0,
percentPosition: true,
});
// fade in and layout Masonry after each image loads
imagesLoaded(".item img").on( 'progress', function( instance, image ) {
$(image.img).fadeIn();
$grid.masonry('layout');
});
I have the same issue (fixed width, different height and I want fixed items) and I resolve with the following code:
//Here I attach the new loaded items (html var) in the #container div.
$("#gallery").append(html).each(function(){
$('#gallery').masonry('reloadItems');
});
$('#gallery').imagesLoaded(function(){
$('#gallery').masonry();
});
If you want to see it working and the effect, you could visit http://pintevent.com to see if is the same desired behavior. Hope it helps!
I'm trying to align four pictures with their captions in a square grid.
I'm using the following HTML code:
<div class="grid">
<div class="post-block">
<img src="img1.jpg" />
<div class="caption">caption1</div>
</div>
<div class="post-block">
<img src="img2.jpg" />
<div class="caption">caption2</div>
</div>
<div class="post-block">
<img src="img3.jpg" />
<div class="caption">caption3</div>
</div>
<div class="post-block">
<img src="img4.jpg" />
<div class="caption">caption4</div>
</div>
</div>
and the following CSS code:
.post-block {
display: inline-block;
position: relative;
text-align: center;
}
If images and captions are the same size everything is ok, but when they are different I get this (an example):
I've tried to align images and captions of different sizes using CSS with no success. I need something like this:
Any help would be appreciated.
Thanks in advance
You'll need to use separate block elements at the same DOM level for the image and the caption to achieve what you've shown in the "RIGHT" image. Right now your caption DIV is nested inside the image DIV, and that's gonna do what you've shown. The caption DIV needs to be outside the image DIV.
You will probably want two separate div wrappers around each 2 photos..
Then align images vertically to bottom.
Vertical align images to bottom
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
then set the styling via inline or your css file
<div style="vertical-align:bottom;">
or
.myWrapClass{
vertical-align:bottom;
}
check out this site... Use the css properties there to keep it responsive
Example
i coded a slide to slip left to right but i don't know why it just runs once time, it does run a first image again when it run last image.Anyone help me,sorry for my bad english. hope you undertands.
HTML
<img src="Britney-Spears.jpg" class="img" />
<img src="Britney-Spears-101[1].JPG" class="img" />
<img src="Britney-Spears-Wallpaper-18.jpg" class="img" />
</div>
CSS
.neoslideshow {position:relative; width:500px; height:260px;
background:#0C9; overflow:hidden;} .neoslideshow img
{position:absolute; top:0;width:400px; height:260px;}
JQUERY
$(document).ready(function() {
$('.neoslideshow img:gt(0)').css('left',-500);
function slide()
{
$('.neoslideshow :first-child').animate({left:"+=500"},"slow").css('left',-500)
.next('img').animate({left:"+=500"},"slow").css('left',-500)
.end().appendTo('.neoslideshow');
};
setInterval(function(){slide();},2000);
});
I am trying to make my vector image clickable. I have searched the internet and can not find the answer. What else do I need in the code?
<div id="logo">
<a href="http://fpmnky.com" target="_self">
<span>
<object width="488" height="115" data="http://fpmnky.com/images/fpmlogo2.svg" type="image/svg+xml">
<img width="488" height="115" src="http://fpmnky.com/images/fpmlogo2.svg" alt="Star"/>
<span>Your browser doesn't support SVG images</span>
</object>
</span>
</a>
<div id="logo">
<a href="http://fpmnky.com" target="_self">
<img src="http://fpmnky.com/images/fpmlogo2.svg" width="488" height="115" alt="fpmlogo" />
</a>