Hello I have a image slider with some pictures. With the help of ajax I am changing the image url , the image is working fine. while in the case of thumbail I can see the changes reflected in console but it is not reflected on the webpage until i resize the page.
console.log(url);
$('.img1').attr("src",url+"/RUST_1.jpg");
$('.img2').attr("src",url+"/RUST_2.jpg");
$('.img1thumb').attr("data-thumb",url+"/RUST_1.jpg");
$('.img2thumb').attr("data-thumb",url+"/RUST_2.jpg");
<ul id="image-gallery" class="gallery list-unstyled cS-hidden">
<li class="img1thumb" data-thumb="../images/<?php echo $item[0]->DESIGN; ?>/<?php echo $item[0]->COLOR_CODE;?>/RUST_1.jpg" >
<img class="img1" class="card-img-top" class="img" src="../images/<?php echo $item[0]->DESIGN; ?>/<?php echo $item[0]->COLOR_CODE; ?>/RUST_1.jpg" alt="Card image" style="width:100%" />
</li>
<li class="img2thumb" data-thumb="../images/<?php echo $item[0]->DESIGN; ?>/<?php echo $item[0]->COLOR_CODE; ?>/RUST_2.jpg" >
<img class="img2" class="card-img-top" class="img" src="../images/<?php echo $item[0]->DESIGN; ?>/<?php echo $item[0]->COLOR_CODE; ?>/RUST_2.jpg" alt="Card image" style="width:100%" />
</li>
</ul>
I found this in lightslider.js
var thumb = $children.eq(i * settings.slideMove).attr('data-thumb');
if (settings.gallery === true) {
pagers += '<li style="width:100%;' + property + ':' + thumbWidth + 'px;' + gutter + ':' + settings.thumbMargin + 'px"><img src="' + thumb + '" /></li>';
} else {
pagers += '<li>' + (i + 1) + '</li>';
}
if (settings.mode === 'slide') {
if ((v) >= w - elSize - settings.slideMargin) {
i = i + 1;
var minPgr = 2;
if (settings.autoWidth) {
pagers += '<li>' + (i + 1) + '</li>';
minPgr = 1;
}
if (i < minPgr) {
pagers = null;
$slide.parent().addClass('noPager');
} else {
$slide.parent().removeClass('noPager');
}
break;
}
}
}
Sorry to waste your time, but lightslider provides a public function to refresh the slider
Step 1: get an object of the light slider
slider = $(document).find('#image-gallery').lightSlider({});
Step 2: call refresh function after you change the images url
slider.refresh();
Source: https://github.com/sachinchoolur/lightslider/blob/aa6c01e1e0fbf180eed67447471dfc24d29a3ae1/README.md
Related
how to get dynamic data from database in Wordpress ajax if their is already a query is running inside a function in Wordpress
<script type="text/javascript" >
var ajaxurl = "<?php echo admin_url('admin-ajax.php');?>";
jQuery(document).ready(function($) {
var data = {
'action': 'wa_action'
};
$.post(ajaxurl, data, function(result) {
var contactList = JSON.parse(result);
console.log(contactList);
var contents = '<ul id="whatsapps" class="list" >';
contactList.forEach(contact => {
contents += '<li class="child">';
contents += '<a href="https://wa.me/+91'+contact.contact_number+'" target="_blank">';
contents += '<img src="<?php echo PLUGIN_URL."/CustomPlugin/assets/images/whatsapp.png" ?>" class="img-fluid" target="_blank" alt="logo" />';
contents += '<span>'+contact.name + '(' + contact.designation +')' + '</span>';
contents += '</a>';
contents += '</li>';
});
contents += '<li class="parent"><a><img src="<?php echo PLUGIN_URL."/CustomPlugin/assets/images/whatsapp.png" ?>" class="img-fluid" target="_blank" alt="logo"></a></li>';
contents += '</ul>';
$('body').append(contents);
$("#whatsapps .parent").click(function () {
$("#whatsapps").toggleClass("show");
});
});
});
</script>
How to add CSS for positioning here
Hello I Am Working On A Startup and I Have A Huge Problem In My Project.
In Searching Page User Can Search By Different Item And Ads Showed.
I Wanna Per Each Ad In The Picture Area Shows Picture By Slider.
Let Me Show By Pic .
This Is Searching Page
Searchin_Page
I Wanna Use Slider For Each Ad That Shows But Its Dose not Work True . . .
This Is My Jquery Code
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-white", "");
}
x[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " w3-white";
}
And This Is Html Side . . .
<div class="Image_Area_Panel">
<div class="w3-content w3-display-container" style="max-width:800px">
<img class="mySlides" src="http://localhost/Ajency/Public/456d6ef5aae4e33926a4c592aa5210a5--sexy-men-hot-men.jpg">
<img class="mySlides" src="http://localhost/Ajency/Public/620b1b643b4d40bef759a386764fc630.jpg">
<img class="mySlides" src="http://localhost/Ajency/Public/Brant-daugherty-cuff.jpg">
<div class="w3-center w3-container w3-section w3-large w3-text-white w3-display-bottommiddle Aroos" style="width:100%">
<div class="AreaBox">
<div class="w3-left w3-hover-text-khaki" onclick="plusDivs(-1)">❮</div>
<div class="w3-right w3-hover-text-khaki" onclick="plusDivs(1)">❯</div>
</div>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(1)"></span>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(2)"></span>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(3)"></span>
</div>
</div>
Sorry For My English Ability
I am showing images in list with having next and previous button.
I have use this jquery in for loop so that it can more than one.
list1:
Prev <ul><li> img1 img2 img3....</li></ul> Next
list2:
Prev <ul><li> img1 img2 img3....</li></ul> Next
if i have three different image list on same page if i click on next Or prev of 1st list then its apply for all list.
how can i apply it for that particular list to move Next and prev.
I have used the code from ths link:http://css-plus.com/2010/09/create-your-own-jquery-image-slider/
i have used folloeing code:
Jquery:
$(document).ready(function(){
// Gallery
if(jQuery(".gallery").length){
// Declare variables
var totalImages = jQuery(".gallery > li").length,
imageWidth = jQuery(".gallery > li:first").outerWidth(true),
totalWidth = imageWidth * totalImages,
visibleImages = Math.round(jQuery(".gallery-wrap").width() / imageWidth),
visibleWidth = visibleImages * imageWidth,
stopPosition = (visibleWidth - totalWidth);
jQuery(".gallery").width(totalWidth);
jQuery("#gallery-prev").click(function(){
if(jQuery(".gallery").position().left < 0 && !jQuery(".gallery").is(":animated")){
jQuery(".gallery").animate({left : "+=" + imageWidth + "px"});
}
return false;
});
jQuery("#gallery-next").click(function(){
if(jQuery(".gallery").position().left > stopPosition && !jQuery(".gallery").is(":animated")){
jQuery(".gallery").animate({left : "-=" + imageWidth + "px"});
}
return false;
});
}
});
Html and php:
<?php foreach($records as $row) :?>
<div id="gallery-wrap">
<ul id="gallery" class="gallery">
<?php foreach($row['images'] as $image) :?>
<li>
<img src="<?php echo base_url();?>uploads/<?php echo $image['img']; ?> />
</li>
<?php endforeach ;?>
</ul>
</div>
<div id="gallery-controls" class="gallery-controls">
<a href="#" id="gallery-prev" >Prev</a>
<a href="#" id="gallery-next" >Next</a>
</div>
<?php endforeach ;?>
ok first of all....
1) IDs should always be unique... but in your case you have elements with same ID since it is in loop.. so either change it and makeit unique OR you can change it to class in your HTML code...
<div class="gallery-wrap">
-----^^---- change to class...
2) since you are using class , all your ID selector i.e # should be replaced by class selector . in your jquery code.
jQuery(".gallery-prev").click(function(){
--------^------ here
changes in your
HTML
<div class="galleryDisplayBlock"> //add new div
<div class="gallery-wrap">
<ul class="gallery">
<?php foreach($row['images'] as $image) :?>
<li>
<img src="<?php echo base_url();?>uploads/<?php echo $image['img']; ?> />
</li>
<?php endforeach ;?>
</ul>
</div>
<div class="gallery-controls">
<a href="#" class="gallery-prev" >Prev</a>
<a href="#" class="gallery-next" >Next</a>
</div>
</div>
JQuery
jQuery(".gallery-prev").click(function(){
var thisGallery=jQuery(this).parent();
if(thisGallery.find(".gallery").position().left < 0 && !thisGallery.find(".gallery").is(":animated")){
thisGallery.find(".gallery").animate({left : "+=" + imageWidth + "px"});
}
return false;
});
jQuery(".gallery-next").click(function(){
var thisGallery=jQuery(this).parent();
if(thisGallery.find(".gallery").position().left > stopPosition && !thisGallery.find(".gallery").is(":animated")){
thisGallery.find(".gallery").animate({left : "-=" + imageWidth + "px"});
}
return false;
});
I have this code which I found on Stack a few weeks ago.
<script type="text/javascript">
$(document).ready(function() {
// I added the video size here in case you wanted to modify it more easily
var vidWidth = 300; // 425;
var vidHeight = 200; // 344;
var obj = '<object width="' + vidWidth + '" height="' + vidHeight + '">' + '<param name="movie" value="http://www.youtube.com/v/[vid]&hl=en&fs=1">' + '</param><param name="allowFullScreen" value="true"></param><param ' + 'name="allowscriptaccess" value="always"></param><em' + 'bed src="http://www.youtube.com/v/[vid]&hl=en&fs=1" ' + 'type="application/x-shockwave-flash" allowscriptaccess="always" ' + 'allowfullscreen="true" width="' + vidWidth + '" ' + 'height="' + vidHeight + '"></embed></object> ';
$('.posthold:contains("youtube.com/watch")').each(function() {
var that = $(this);
var vid = that.html().match(/v=([\w\-]+)/g); // end up with v=oHg5SJYRHA0
that.html(function(i, h) {
return h.replace(/(http:\/\/www.youtube.com\/watch\?v=+\S+\S?)/g, '');
});
if (vid.length) {
$.each(vid, function(i) {
that.append(obj.replace(/\[vid\]/g, this.replace('v=', '')));
});
}
});
});
</script>
It works great at embeding videos from url's. But I have a small problem with it that I have been trying to solve but i keep breaking the code.
Basically I have the following div setup
<div class="grid_10 alpha omega posthold" >
<div class="clearfix">
<div class="grid_2 alpha">
<img src="/images/no-image/logo_default.jpg" width="100" height="100" />
</a></div>
<div class="grid_8 omega">
<h1>Some Name Here</h1>
<p>Some Comment here</p>
</div>
</div>
</div>
Im trying to get the video to appear directly after the closing paragraph tag where it says some comment here. The user enters the video as part of a post. I store the post in a database and when I pull the post out I swap the url from youtube to the embed code. This is a repeating div so there maybe many instances that a video appears. Is this even possible. At the minute the video appears after the last closing div tag.
I use Highslide jQuery Gallery to load albums and their thumbnails on a single page.
Users can click the thumbnail and each album then loads.
The website runs slow if I have more than 10 albums per page (due to loading thumbs and pics)
I use base64 encoding on the data in the database.
How can I load only the thumbails instead of whole albums?
The album will only load once the user has clicked the thumbnail..
<?php
//vars
$albumsQuery = mysql_query("select * from albums");
$album_count = 0;
// start loop
while ($album = mysql_fetch_array($albumsQuery)) {
$album_count++;
$unserializePhotos = unserialize(base64_decode($album['photos']));
$unserializeDescriptions = unserialize(base64_decode($album['descriptions']));
$firstPhoto = '';
$first_photo_count = 0;
foreach ($unserializePhotos as $k => $v) {
if ($first_photo_count == 0) {
$firstPhoto = $v['name'];
}
$first_photo_count++;
}
$first_desc_count = 0;
foreach ($unserializeDescriptions as $k => $v) {
$unserializeDescriptions[$k]=htmlspecialchars($v);
if ($first_desc_count == 0) {
$firstDesc = htmlspecialchars($v);
}
$first_desc_count++;
}
?>
<div class="highslide-gallery">
<a class='highslide' id="thumb<?php echo $album_count; ?>" href='/albums/<?php echo $firstPhoto; ?>' onclick="return hs.expand(this, {slideshowGroup: <?php echo $album_count; ?>})">
<img src='/albums/<?php echo $firstPhoto; ?>' height="100px" width="100px" />
</a>
<div class="hidden-container">
<?php
$photoDescIndex = 0;
foreach ($unserializePhotos as $k => $v) {
if ($v['name'] != '' && $v['name'] != $firstPhoto){
?>
<a class='highslide' href='/albums/<?php echo $v['name']; ?>' onclick="return hs.expand(this, {slideshowGroup: <?php echo $album_count; ?>})">
<img src='/albums/<?php echo $v['name']; ?>' />
</a>
<?php
}
$photoDescIndex++;
}
?>
</div>
You are loading full image into thumbnail: <img src='/albums/<?php echo $firstPhoto; ?>' height="100px" width="100px" />. Browser requires more time to load big photo and even more time to resize it. You should prepare small 100x100 thumbnails on the server side.
You should not load all albums <div class="hidden-container">...</div> explicitly. Load content of selected album via AJAX on demand (when user clicked on thumbnail). Additionally you may start to pre-load albums in background after page loading.
Do not assign event handlers directly to each onclick="..." - use event delegation e.g.
$("body").on("click", ".highslide", function() {
var album_count = this.id.slice(5); // a id="thumb<?php echo $album_count; ?>"
var target = $(this).next("div.hidden-container");
// TODO: load album album_count into target via AJAX
// TODO: after load: hs.expand(this, {slideshowGroup: album_count});
});