Select image for larger view using HTML & JavaScript/JQuery - javascript

I would like a simple code using plain html5 and JavaScript/jQuery (without plugins) that upon clicking on an image of a list of images, the clicked image will be shown in a larger image area above.
Here is a HTML snippet:
<!-- Large image holder -->
<div class="large-picture-left">
<p>Property View</p>
<!-- Initially the default picture for the property will be shown -->
<img src="../images/properties/f0001-default.jpg" alt="Property Picture"></a>
</div>
<!-- Text info for the current larger picture -->
<div class="large-picture-left-text">
<br><br>
<!-- Initial default info for default picture -->
<p>Location: <b>London</b></p>
<p>Bedrooms: <b>2</b></p>
<p>Type: <b>Flat</b></p>
<p>Price: <b>£365,000</b></p>
<p>Ref: <b>F0001</b></p>
</div>
</div>
<div style="clear: both"></div>
<br><br>
<div class="container">
<div class="picture-range">
<h2>Photo Range</h2>
<!-- When one of the images below is clicked, to have it shown in the large-picture-left class image holder-->
<div class="img">
<img src="../images/properties/f0001-default.jpg" alt="Default" width="300" height="200">
<div class="desc">Outside<br>5m<sup>2</</sup></div>
</div>
<div class="img">
<img src="../images/properties/f0001-bed1.jpg" alt="Bedroom 1" width="300" height="200">
<div class="desc">Bed 1<br>3m<sup>2</</sup></div>
</div>
<div class="img">
<img src="../images/properties/f0001-bed2.jpg" alt="Bedroom 2" width="300" height="200">
<div class="desc">Bed 2<br>10m<sup>2</</sup></div>
</div>
<div class="img">
<img src="../images/properties/f0001-lounge.jpg" alt="Lounge" width="300" height="200">
<div class="desc">Lounge<br>4m<sup>2</</sup></div>
</div>
<div class="img">
<img src="../images/properties/f0001-kitchen.jpg" alt="Kitchen" width="300" height="200">
<div class="desc">Kitchen<br>3m<sup>2</</sup></div>
</div>
<div class="img">
<img src="../images/properties/f0001-bathroom.jpg" alt="Bathroom" width="300" height="200">
<div class="desc">Bathroom<br>25m<sup>2</</sup></div>
</div>
</div>
</div>
<div style="clear: both"></div>
So, initially the above code will display the default outside photo in the larger area. However, I'm having problems in that, if one of the range pictures is selected, to have the initial default larger photo replaced by the selected picture (and if possible to also have the default photo info replaced by the selected picture info).
Thanks for any help.

This should work
$(document).on("click", ".img", function() {
var newImage = $(this).find("src").attr("src");
var currentImage = $(".large-picture-left img").attr.("src");
$(".large-picture-left img").attr("src", newImage);
$(this).find("src").attr("src", currentImage);
});

Related

How to close a `div` box in Angular when I click outside of it.Without using jQuery

I am working on a site which has been created using Angular. On the homepage I have a Service Box that contains icons which redirects us to different pages. Currently when I click on service box icon it displays the service box:
Now Whenever I click outside of it, it does not close. I am not using jQuery in my project. I have seen many answers for AngularJs but none worked.
Here is my code for service-box.component.html:
<button mat-icon-button (click)="opened = !opened">
<mat-icon>apps</mat-icon>
</button>
<div class="box" [class.opened]="opened">
<div class="tip">
<div class="border"></div>
<div class="foreground"></div>
</div>
<div class="services">
<div class="row">
<a href="https://blog.fossasia.org">
<div class="col">
<div class="img">
<img src="assets/images/blog.png" alt="Fossasia">
</div>
<span>Blogs</span>
</div>
</a>
<a href="https://github.com/fossasia/loklak_search">
<div class="col">
<div class="img">
<img src="assets/images/github.png" alt="Fossasia">
</div>
<span>Github</span>
</div>
</a>
<a href="https://github.com/fossasia/loklak_search/issues">
<div class="col">
<div class="img">
<img src="assets/images/bug.png" alt="Fossasia">
</div>
<span>Bug Report</span>
</div>
</a>
</div>
</div>
<hr />
<div class="services">
<div class="row">
<a href="https://fossasia.org/">
<div class="col">
<div class="img">
<img src="assets/images/fossasia_logo_55x22.png" width="55" height="22" alt="Fossasia">
</div>
<span>FOSSASIA</span>
</div>
</a>
<a href="https://phimp.me">
<div class="col">
<div class="img">
<img src="assets/images/phimpme_64x64.png" width="50" height="50" alt="Phimpme">
</div>
<span>Phimpme</span>
</div>
</a>
<a href="https://susper.com/">
<div class="col">
<div class="img">
<img src="assets/images/susper_60x16.png" width="60" height="16" alt="Susper">
</div>
<span>Susper</span>
</div>
</a>
</div>
<div class="row">
<a href="https://chat.susi.ai/">
<div class="col">
<div class="img">
<img src="assets/images/susi_60x12.png" width="60" height="12" alt="Susi.AI">
</div>
<span>Susi.AI</span>
</div>
</a>
<a href="https://pslab.fossasia.org/">
<div class="col">
<div class="img">
<img src="assets/images/pslab_64x68.png" width="50" height="50" alt="PSLab">
</div>
<span>PSLab</span>
</div>
</a>
<a href="https://eventyay.com/">
<div class="col">
<div class="img">
<img src="assets/images/eventyay.png" width="60" height="18" alt="Eventyay">
</div>
<span>Eventyay</span>
</div>
</a>
</div>
</div>
</div>
service-box.component.ts contains only a public variable opened set to false by default.
I have tried to wrap up whole code of service-box.component.html in a div and used (focusout) event like this:
<div id="side-menu" (focusout)="opened=false">
//Rest of code as in service-box.component.html
</div>
But doing this disables the links in service box.
Any suggestion will be of great help.
You seem to be using #angular/material and therewith the CDK. You should try the CDK's Overlay package.
The overlay package provides a way to open floating panels on the screen.
By setting the attribute hasBackdrop, the overlay will create a backdrop element (= everything outside of your component) and with it a backdropClick #Output event, to which you could bind the closing of your "Service Box".

CSS - AOS animate library - why is slide-in animation distroying my width of entire page?

I am using AOS library for animations. When I use the animation slide-left and slide-right, the width of the page becames wider that the body width, making the whole page look weird. I couldnt find any solution online and the only solution I figured out is if I give the elements which I apply the animation on a width in px (it cannot be bigger than 400px for whatever reason). However, that solution doesnt really work as it destroys up my css too. I have provided a js fiddle so you can see what I mean. Ive been spending hours on that so if anyone can help, I would be truly happy! Thanks!!
https://jsfiddle.net/Lca8n0ue/
code:
<div style="background-color:red; height:300px;"></div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class="container-fluid">
<div class="row center-block wrapper">
<div class="col-sm-6 test" data-aos="slide-right">
<h2 class="text-center">title</h2>
<p class="text-center">app</p>
<div>
<img class="img-fluid center-block" width="350" height="320" src="http://unsplash.imgix.net/reserve/9Fx2auQ4yoHM8OpWA8qw__MG_5265.jpg?fit=crop&fm=jpg&h=700&q=75&w=1050" alt="">
</div>
</div>
<div class="col-sm-6 test2" data-aos="slide-left">
<h2 class="text-center">title</h2>
<p class="text-center">appp</p>
<div>
<img class="img-fluid center-block" width="350" height="320" src="http://unsplash.imgix.net/reserve/9Fx2auQ4yoHM8OpWA8qw__MG_5265.jpg?fit=crop&fm=jpg&h=700&q=75&w=1050" alt="">
</div>
</div>
<div class="col-sm-6 test" data-aos="slide-right">
<h2 class="text-center">title</h2>
<p class="text-center">app</p>
<div>
<img class="img-fluid center-block" width="350" height="320" src="http://unsplash.imgix.net/reserve/9Fx2auQ4yoHM8OpWA8qw__MG_5265.jpg?fit=crop&fm=jpg&h=700&q=75&w=1050" alt="">
</div>
</div>
<div class="col-sm-6 test2" data-aos="slide-left">
<h2 class="text-center">title</h2>
<p class="text-center">appp</p>
<div>
<img class="img-fluid center-block" width="350" height="320" src="http://unsplash.imgix.net/reserve/9Fx2auQ4yoHM8OpWA8qw__MG_5265.jpg?fit=crop&fm=jpg&h=700&q=75&w=1050" alt="">
</div>
</div>
</div>
</div>
js:
AOS.init();
ONLY THING THAT HELPS BUT RUINS CSS IS:
.test{
width: 400px;
}
.test2{
width: 400px;
}
Although I'm not completely sure WHY is it so (I had the same problem a lot of time) there is another way to fix this.
Just set overflow-x: hidden on the parent element.
In your case this would be .container-fluid.

How do I get the src of images when clicked on Fabric.js canvas?

i'm making a website with Fabricjs. One div is going to be the canvas and another is going to have lots of images (hundreds). I want to be able to click on the images so that they pop up in the canvas. My question is; how do i get the src of the images when clicked on so that an img node goes into the canvas node. Should i make an array of addEventl... for each of the images?
(writing in javascript)
thanks as always :)
<!doctype html>
<html lang="en";>
<head>
<meta charset="utf-8" />
<title>CustomCase</title>
<link rel="stylesheet" href="HeaderFooter.css">
<link rel="stylesheet" href="SkapaDesign.css">
<script src="Jquery.js"></script>
<script src="Fabric.js"></script>
<script src="Canvas.js"></script>
</head>
<body>
<div id="Wrapper">
<header id="Header">
Om Oss
Välj Design
<img id="Logo" src=LogotypHemsida.png>
Skapa Design
Hjälp
</header>
<section id="Body">
<img id="UpperShadow" src=NeråtSkugga.png>
<div id="LeftColumn">
<div id="TextMode">
</div>
<div id="CanvasContainer">
<canvas id="Canvas" width="270px" height="519px"></canvas>
</div>
<div id="LayerMode">
</div>
<div id="IPhoneMode">
</div>
</div>
<div id="RightColumn">
<div id="TextureMode">
</div>
<div id="TextureFilter">
</div>
<div id="TextureView">
<div id="TextureViewInside">
<div id="images">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
</div>
</div>
</div>
</div>
<img id="LowerShadow" src=UppåtSkugga.png>
</section>
<footer id="Footer">
<div id="FooterSpace"></div>
<div id="FooterColumnLeft">
Välj Design
Skapa Design
Om Oss
Hjälp
</div>
<div id="FooterDevider">
</div>
<div id="FooterColumnRight">
<div id="Facebook">
<img id="FacebookLogo" src=FacebookLogo.png>
Gilla oss på Facebook
</div>
<div id="Twitter">
<img id="TwitterLogo" src=TwitterLogo.png>
Följ oss på Twitter
</div>
</div>
<div id="FooterSpace"></div>
<div id="BottomColor"></div>
</footer>
</div>
</body>
</html>
You don't have to declare onclick for each img.
Try this: http://jsfiddle.net/cEh93/
$("#images img").click(function() {
var getsource = $(this).attr("src");
alert(getsource);
});
You don't need the onclick on each image, you can attach a jQuery event handler to all images and get their src attribute (this will output the image src to the console when the image is clicked):
jQuery(document).ready(function()
jQuery("#images img").on( "click", function() {
console.log( jQuery( this ).attr('src') );
});
}); // ready
You can set the retrieve of SRC only attaching event for upper DIV (using JS), like that:
<div id="images" onclick="getSelectedImageURL(event);">
<input type="image" src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
<img src="FärgadePapper.png">
<img src="Hajar.png">
<img src="Labyrint.png">
<img src="Martini.png">
</div>
To get current selected image SRC on click event...
function getSelectedImageURL(event){
if(event.target.localName.toUpperCase() == 'IMG')
alert(event.target.src);
}

iDangerous Swiper not detecting swipe

So I'm creating a image marquee for a mobile site that uses iDangerous Swiper plugin and have run into a issue when trying to use it. Following the set up based on the site, found here, I built my demo page to the exact spec of their demo. But for some reason, the function isn't running and I cant swipe to the next div. Being a mobile site, I'm using Jquery and Jquery Mobile. Any ideas?
<body>
<div class="swiper-container">
<div class="swiper-wrapper">
<!--First Slide-->
<div class="swiper-slide">
<img src="img/1.png" width="200" height="118">
</div>
<!--Second Slide-->
<div class="swiper-slide">
<img src="img/2.png" width="200" height="118">
</div>
<!--Third Slide-->
<div class="swiper-slide">
<img src="img/3.png" width="200" height="118">
</div>
<!--Fourth Slide-->
<div class="swiper-slide">
<img src="img/4.png" width="200" height="118">
</div>
<!--Fifth Slide-->
<div class="swiper-slide">
<img src="img/5.png" width="200" height="118">
</div>
</div>
</div>
<script>
$(function(){
var mySwiper = $('.swiper-container').swiper(options);
})
</script>
</body>
To use buttons for Swiper you need to use .swipeNext() and .swipePrev() methods on mySwiper object like:
<!-- Add somewhere in HTML your buttons:-->
<span class="button-next">Next button</span>
<span class="button-prev">Previous button</span>
<script>
$(function(){
var mySwiper = $('.swiper-container').swiper();
//"Next" button - some HTML element with "button-next" class
$('.button-next').click(function(){mySwiper.swipeNext()})
//"Prev" button - some HTML element with "button-prev" class
$('.button-prev').click(function(){mySwiper.swipePrev()})
})
</script>
iDangero.us here!:) Your HTML is correct. But what is "options" in your example? this should be an object with parameters or if you want to use default options then just remove "options" word from your example like: var mySwiper=$('.swiper-container').swiper()

Jquery Cycle and Pixastic fast blur

I am trying to cycle my image and blur the background image but the problem is it only blurs the first image but not the next image.
<div id="banner_images">
<div id="banner_cycle_wrapper">
<div id="banner_bg_cycle">
<img src="source.png" class="blur">
</div>
<div id="banner_cycle_container">
<img src="source.png">
</div>
</div>
<div id="banner_cycle_wrapper" >
<div id="banner_bg_cycle">
<img alt="" src="source.png" class="blur">
</div>
<div id="banner_cycle_container">
<img src="source.png">
</div>
</div>
</div>
$('#banner_images').cycle({
fx: 'fade',
timeout: 2000
});
$(".blur").pixastic("blurfast", {amount:0.5});
I think you are missing CLASS to add in that
class="blur"
this should be added to each image you want to have the same effect.
Updated Code:
<div id="banner_images">
<div id="banner_cycle_wrapper">
<div id="banner_bg_cycle">
<img alt="" src="source.png"/>
</div>
<div id="banner_cycle_container">
<img alt="" src="img1.png" class="blur" />
<img alt="" src="img2.png" class="blur" />
</div>
</div>
</div>
I hope this will help :)

Categories

Resources