combine two scrolls - gallery with horizontal scroll - javascript

I'm trying to create a simple gallery with vertical scroll. This scroll should cause two things: 1.move small pictures below the big photo and 2.change the source of the big photo (so it will change the big photo in result). I'm not got at describing what exactly I want to do so here is the code:
html:
<div class="container">
<div class="bigPhoto">
<img />
</div>
<ul>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=1' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=2' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=3' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=4' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=5' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=6' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=7' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=8' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=9' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=10' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=12' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=13' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=14' /></li>
<li><img src='http://dummyimage.com/600x400/000/fff.jpg&text=15' /></li>
</ul>
<input type=range id='scroller' />
css:
ul {
border:1px solid orange;
list-style-type: none;
text-align: center;
margin:0;
padding:0;
max-height: 50px;
white-space: nowrap;
overflow-y: hidden;
overflow-x: scroll;}
li {
display:inline-block;}
img {
width:50px;}
.fullSize {
width:100%;
height:100%;}
js:
var smallImages = document.querySelectorAll('li img');
var bigPhotoDiv = document.querySelector('.bigPhoto img');
var scroller = document.querySelector('#scroller');
bigPhotoDiv.src = smallImages[0].src;
bigPhotoDiv.classList.add('fullSize')
scroller.max = smallImages.length-1;
scroller.addEventListener('change', function(event) {
var currentLink = smallImages[scroller.value].src;
bigPhotoDiv.src = currentLink;
});
https://jsfiddle.net/0d2z26e1/
Now I have two scrolls, lower for changing my bigPhoto and upper for moving small images. Is it possible to combine them into one?

Related

Thumbnail grid is displayed in a column

I'm trying to create a grid of several thumbnail images but I have the same problem, which is that my images are in columns. Indeed, I have one image per line, whereas I want as many as possible.
Here is an example of what I want to achieve:
https://codepen.io/pjhooker/pen/lFuDK
<div>
<ul>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
<li><img src="http://placehold.it/150x150" /></li>
</ul>
</div
The problem is that even with this code my images remain in columns underneath each other
Here's what I have in my code:
<template>
<div>
<div>
<div class="hex-row even">
<Hexagon v-for="n in 7" v-bind:key="n"/>
</div>
<div class="hex-row">
<Hexagon v-for="n in 7" v-bind:key="n"/>
</div>
<div class="hex-row even">
<Hexagon v-for="n in 7" v-bind:key="n"/>
</div>
</div>
<div style="margin-top: 300px;">
<ul>
<li v-for="img in images" v-bind:key=img>
<v-img max-width="48px" max-height="48px" v-bind:src=img />
</li>
</ul>
</div>
</div>
</template>
<style scoped>
.hex-row {
clear: left;
}
.hex-row.even {
margin-left: 53px;
}
ul {
list-style: none;
}
li img {
float: left;
margin: 10px;
border: 5px solid #fff;
transition: all .3s ease;
}
</style>
<script>
import Hexagon from './Hexagon'
export default {
data: () => ({
images : [url, url, url...]
}),
components: {
Hexagon,
}
}
</script>
With the code above, I have images of 48px * 48px that are arranged one below the other.
I want the images to be next to each other. As soon as there is no more space on the line, the sequence continues on the next line
You should add a display:flex; flex-wrap:wrap to the parent container
Here is a similar pen using div elements instead of li
https://codepen.io/chrismclarke/pen/ExYZxbG
Apply following code in your CSS.
ul{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

How do I allow the user to set the number of columns in a grid image layout?

What are some ways I could achieve this layout? I'm going to have a grid of images. Each image will be the same size. I'd like to scale the images up and down based on a user setting which defines the number of columns in the grid. The user setting will be stored in HTML5 local storage.
I've looked at Masonry, but I wonder if that might be overkill since all the images are the same size and the grid will be uniform. Masonry lets me define the column width, which can get me where I need to be, but I'd love something that let me define the number of columns directly. I've also considered using Flexbox for the layout, but I'm not sure how to then change the number of columns with a user-selectable setting. I want to go as lightweight in terms of development overhead as possible with this solution.
Here are some images to help visualize what I want. Here, the user has selected a 5-column layout.
Here are 4- and 3-column layouts.
If your number of options is known, then you can create a container style for each scenario.
.five-col .col {
float: left;
width: 20%;
}
And structure your html as...
<ul class="five-col">
<li class="col"> image </li>
...
</ul>
Create a new container style for each column layout, eg. .four-col .eight-col and just toggle between them.
This does require you to know ahead of time the number of columns you will allow them to choose between, but an 'n' solution might allow the user to create something silly like 20+ columns so vetting the options ahead of time has it's advantages.
If you are interested in a framework that gives you something similar, check out http://unsemantic.com/ or http://960.gs/.
Id do it like this:
*
{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body
{
margin:0;
padding: 0px;
}
.gallery
{
padding: 15px;
margin:0;
list-style: none;
overflow: hidden;
}
.gallery > li
{
margin: 0px;
padding: 2.5px 5px;
float: left;
text-align: center;
}
.gallery > li img
{
max-width: 100%;
}
.gallery.items2 > li
{
width: 50%;
}
.gallery.items3 > li
{
width: 33.333%;
}
.gallery.items4 > li
{
width: 25%;
}
.gallery.items5 > li
{
width: 20%;
}
.gallery.items6 > li
{
width: 16.666%;
}
Some jQuery (or JS)
$("#grid-range").change(function(){
var griditems = $(this).val();
$("#gallery").removeClass("items2 items3 items4 items5 items6");
$("#gallery").addClass("items"+griditems);
});
This HTML:
<input type="range" min="2" id="grid-range" max="6" value="2" step="1" name="power" />
<ul id="gallery" class="gallery items2">
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
<li><img src="http://www.placehold.it/200x200" /></li>
</ul>
Here is a demo: http://jsfiddle.net/eEnkf/4/

How to create horizontal scroll bar for a div

I have the following items.
left arrow slide1 slide2 slide3 slide4 slide5... right arrow
I want to be able to have horizontal scroll bar in my div.
I have something like this
<section id='slide-container'>
<div id='left-nav'><a href='#'><img src='images/left-nav.png'/></a></div>
<ul id='slide-list'>
<li><img src='images/slide1.png' /></li>
<li><img src='images/slide2.png' /></li>
<li><img src='images/slide3.png' /></li>
<li><img src='images/slide4.png' /></li>
<li><img src='images/slide5.png' /></li>
<li><img src='images/slide1.png' /></li>
<li><img src='images/slide2.png' /></li>
<li><img src='images/slide3.png' /></li>
<li><img src='images/slide4.png' /></li>
<li><img src='images/slide5.png' /></li>
</ul>
</section>
css
#slide-container{
width: 970px;
height: 190px;
line-height: 190px;
border:solid 1px #EEEEEE;
position: relative;
overflow: scroll;
}
I can only see the vertical scroll bar and my slides are vertically aligned. I was hoping someone here can help me to keep my slides aligned horizontally and show a scroll bar for it.
My brain is fried...
Thanks a lot!
To #slide-container add white-space: nowrap; overflow: auto;.
For #slide-list li add display: inline-block;.
Please replace your style with this
#slide-container{
width: 970px;
height: 190px;
line-height: 190px;
border:solid 1px #EEEEEE;
position: relative;
overflow-y:hidden;
overflow-x: scroll;
display:block;
}
#slide-list
{
width:1500px; /*i put this for see the scrolling/*
}

multiple bxSlider instances on one page

I have four slideshows on one page that I want to just run in loops, using bxSlider
I'm great with mark-up and CSS, but not yet very proficient with javascript. I think I must be missing a key element, because none of the slideshows are currently working. I would love some help getting all four to work. Thanks!
JS:
<script type="text/javascript" src="js/jquery.bxslider.min.js"></script>
<script type="text/javascript">
$('#slider1').bxSlider({
auto: true,
autoControls: true,
pause: 3000,
slideMargin: 20
});
$('#slider2').bxSlider({
auto: true,
autoControls: true,
pause: 3000,
slideMargin: 20
});
$('#slider3').bxSlider({
auto: true,
autoControls: true,
pause: 3000,
slideMargin: 20
});
$('#slider4').bxSlider({
auto: true,
autoControls: true,
pause: 3000,
slideMargin: 20
});
</script>
CSS:
.slider {
position: relative;
float: right;
padding-right: 400px;
margin-left: 40px;
height: 350px;
}
.slider img {
position: absolute;
max-width: 350px;
height: auto;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
top: 0;
left: 0;
z-index: 8;
}
Mark-up:
<div>
<div class="slider">
<ul id="slider1">
<li><img src="images/.../art-1.jpg" /></li>
<li><img src="images/.../art-2.jpg" /></li>
<li><img src="images/.../art-3.jpg" /></li>
<li><img src="images/.../art-4.jpg" /></li>
<li><img src="images/.../art-5.jpg" /></li>
</ul>
</div>
</div>
<div>
<div class="slider">
<ul id="slider2">
<li><img src="images/.../bnl-1.jpg" /></li>
<li><img src="images/.../bnl-2.jpg" /></li>
<li><img src="images/.../bnl-3.jpg" /></li>
<li><img src="images/.../bnl-4.jpg" /></li>
<li><img src="images/.../bnl-5.jpg" /></li>
</ul>
</div>
</div>
<div>
<div class="slider">
<ul id="slider3">
<li><img src="images/.../bge-1.jpg" /></li>
<li><img src="images/.../bge-2.jpg" /></li>
<li><img src="images/.../bge-3.jpg" /></li>
<li><img src="images/.../bge-4.jpg" /></li>
<li><img src="images/.../bge-5.jpg" /></li>
</ul>
</div>
</div>
<div>
<div class="slider">
<ul id="slider4">
<li><img src="images/.../rtb-1.jpg" /></li>
<li><img src="images/.../rtb-2.jpg" /></li>
<li><img src="images/.../rtb-3.jpg" /></li>
<li><img src="images/.../rtb-4.jpg" /></li>
<li><img src="images/.../rtb-5.jpg" /></li>
</ul>
</div>
</div>

jQuery submenu position bug

I`m trying to create menu which is opening on clicking parent element and closeing on mouseleave from that one which was opened a while ago. It should work from left to right
Here is
<ul class="menuFirst">
<li><img src="img/ico1.png"></li>
<ul class="">
<li><img src="img/ico2.png" alt="submoduł1"></li>
<li><img src="img/ico2.png" alt="submoduł2"></li>
<li><img src="img/ico2.png" alt="submoduł3"></li>
</ul>
<li><img src="img/ico1.png"></li>
<ul class="menuSecond">
<li><img src="img/ico2.png" alt="submoduł1"></li>
<li><img src="img/ico2.png" alt="submoduł2"></li>
<li><img src="img/ico2.png" alt="submoduł3"></li>
</ul>
<li><img src="img/ico1.png"></li>
<ul class="menuSecond">
<li><img src="img/ico2.png" alt="submoduł1"></li>
<li><img src="img/ico2.png" alt="submoduł2"></li>
<li><img src="img/ico2.png" alt="submoduł3"></li>
</ul>
</ul>
Here is CSS
ul.menuFirst{
list-style-type: none;
border-top: #AAA solid 3px;
border-right: #AAA solid 3px;
border-bottom: #AAA solid 2px;
position: absolute;
left: 0px;
top: 70px;}
ul.menuFirst li{
background: #DDD;
border-bottom: #AAA solid 1px;
}
ul.menuFirst li img{
margin:5px;
}
ul.menuFirst ul{
display: none;
}
ul.menuFirst ul.menuSecond {
list-style: none;
display: table;
position: absolute;
left: 30px;
}
ul.menuFirst ul.menuSecond li{
display: table-cell;
}
And here is jQuery
<script>
$(document).ready(function(){
$("ul.menuFirst li").click(function(){
$(this).next().toggle();
var ypos= $(this).next().position();
alert(ypos.top);
$(this).next().css('top','-=38');
$('ul.menuFirst ul.menuSecond').one('mouseleave',function(){
$(this).css('top', '+=38').toggle();
});
});
});
It works for 1st element but it's pretty buggy. When I'm trying to add .animate() It just didn't work. So I`ve decided to take step back and unbug this one but i don't know how. It should looks like this:
Your HTML is not correct use this
<ul class="menuFirst">
<li><img src="img/ico1.png">
<ul class="">
<li><img src="img/ico2.png" alt="submodul1"></li>
<li><img src="img/ico2.png" alt="submodul2"></li>
<li><img src="img/ico2.png" alt="submodul3"></li>
</ul>
</li>
<li><img src="img/ico1.png">
<ul class="menuSecond">
<li><img src="img/ico2.png" alt="submodul1"></li>
<li><img src="img/ico2.png" alt="submodul2"></li>
<li><img src="img/ico2.png" alt="submodul3"></li>
</ul>
</li>
<li><img src="img/ico1.png">
<ul class="menuSecond">
<li><img src="img/ico2.png" alt="submodul1"></li>
<li><img src="img/ico2.png" alt="submodul2"></li>
<li><img src="img/ico2.png" alt="submodul3"></li>
</ul>
</li>
</ul>
Ok, I`ve fix it....
$('ul.menuFirst ul').each(function(){
$(this).css('top', '-=38').hide();
});
This is executing where DOM is ready I don't need to change position each time while I`m opening or closeing it.
$("ul.menuFirst li").click(function(){
$(this).next().toggle("slide",
{direction: "left"})
});
$('ul.menuFirst ul.menuSecond').mouseleave(function(){
$(this).hide("slide",
{direction: "left"});
Nextly I`m ussing this to animate it.

Categories

Resources