Rollover Animation for Masonry JQuery - php

I am using the jquery masonry on my website http://zakiyadavidson.com.
I am wanting to do a rollover effect such as what is on http://damiencorrell.com/. My end result would be when you rollover a picture text appears.
I attempted to add in the below js code:
//Set div dimensions equal to image's dimensions:
$('#image_holder1').width($('#image_1').width());
$('#image_holder1').height($('#image_1').height());
$('#image_1').each(function(){
//set css of right:
$(this).css({right: '-' + $(this).width() + 'px'})})
//tell the browser what to do when hovering on the div:
$('#image_holder1').hover(function() {
//when mouse hover:
$('#image_0').animate({
right: '-' + $(this).width() + 'px'
}, /*duration*/ 360, /*ease*/ 'swing');
$('#image_1').animate({
right: '0px'
}, /*duration*/ 360, /*ease*/ 'swing');
},
function() {
//when mouse out, no hover:
$('#image_0').animate({
right: '0px'
}, /*duration*/ 360, /*ease*/ 'swing');
$('#image_1').animate({
right: '-' + $(this).width() + 'px'
}, /*duration*/ 360, /*ease*/ 'swing');
});​
Along with the above js code I added in the css block below:
#image_holder1 {
overflow: hidden;
}
.image1 {
position: absolute;
}​
The masonry html looks like the below with the above added changes:
<div class="box photo col3" id="image_holder1">
<img id="image_0" src="image_17.jpg" title="Family First" alt="Family First" />
<img id="image_1" src="image_17Hover.jpg" />
...
Rather than the images showing as you mouse over you are able to see it soon as you load the page. The masonry layout is now not aligned properly. Is it because I have the function under the onload event? Any assistance is greatly appreciated.

I figured it out!!!
A simple Jquery script does the trick and will allow you to do as many pictures as necessary!!
<script>
jQuery(function () {
$(".imgSwap img").hover(function () {
this.src = this.src.replace("_off", "_on");
}, function () {
this.src = this.src.replace("_on", "_off");
});
});
</script>
I hope this helps others of you.
You can check out the working script by going to my site http://zakiyadavidson.com

Related

Can't retrieve a specific portion of an HTML file (single.php) with AJAX in Wordpress

I have a small problem with a feature that I'm trying to implement on my site. I want when I click on an excerpt from a blog post on my homepage that the content of the article (single.php) opens in a modal window.
I use jQuery and Ajax to do that and it works really well except that Ajax fetches me the entire contents of single.php file (ie the header with scripts, styles, doctype, footer, etc.). I would just like to get the div (#PostContainer) that includes the title of the article and the content.
You will probably tell me to just delete my header and footer of the single.php file, but this is not possible because it is important to keep intact my file to be able to access from the address of the blog post (www.mydomainname.com/blog-post1).
It turns out that I am not at all familiar with WordPress :/ This is the first time I build a theme. The codes I shared with you run like a charm on WordPress but recovers me all of my single.php file (header + content in my div #postContainer + footer). I would like to recover only the contents of my div #postContainer.
I'm stuck :/
Someone would help me please ?
Thank you so so much for your time !
Here are my codes :
HTML :
<a class="hs-inner-click modal" data-content="<?php the_permalink(); ?>" rel="<?php the_ID(); ?>" href="<?php the_permalink(); ?>">
CSS :
.modal-window {
position: fixed;
left: 50%;
top: 50px;
width: 720px;
background-color: #fff;
transform: translate(-50%, 0);
z-index: 11;
}
.modal-shade {
position: fixed;
height: 100%;
width: 100%;
background-color: rgba(0, 0, 0, .7);
z-index: 10;
}
.modal-close {
position: absolute;
top: 10px;
right: 10px;
}
JQUERY & AJAX in a JS file :
(function($) {
$.fn.modal = function (opt) {
var settings, createModal, closeModal, body;
settings = $.extend({
'modal': 'jquery-modal',
'close': 'jquery-modal-close',
'closeText':'',
'shade': 'jquery-modal-shade'
}, opt);
body = $('body');
closeModal = function(modal, shade) {
modal.remove();
shade.remove();
};
createModal = function(data) {
var shade, close, modal;
shade =$('<div />', {
class: settings.shade
}).on('click', function() {
closeModal(modal, shade);
});
close =$('<a />', {
text: settings.closeText,
class: settings.close,
href: '#'
}).on('click', function(e) {
closeModal(modal, shade);
e.preventDefault();
});
modal =$('<div />', {
html: data,
class: settings.modal
}).append(close);
body.prepend(shade, modal);
};
this.on('click', function(e) {
var self =$(this);
$.ajax({
url:self.data('content'),
type: 'get',
cache: false,
}).done(function(data) {
createModal(data);
}).error(function() {
createModal('There is a mistake');
});
e.preventDefault();
});
};
})(jQuery);
I would suggest to use WordPress REST API V2 for the request without the need of selecting a div or loading single.php without header & footer.
This will allow you to load post content by just calling an endpoint similar to this: /wp-json/wp/v2/posts/<id>
Full API reference here.
Alternatively I am not sure if it will work but jquery code might help you (execute onload of modal): $("#jquery-modal").load("www.mydomainname.com/blog-post1 #postContainer");
ADDITIONALLY: On ajax success append content on a dummy div and use it to find only the part of the page you need and return it.
That's the way jquery load() actually works if you check the source.
jQuery( "<div>" ).append( jQuery.parseHTML(data) ).find("#postContainer");

I want to trigger this jQuery on 1000px or less. Can I do that with PHP?

I am using this jquery to move towards a map after a selection with . I want to only do it when the browser is less than 1000px but the layout shifts to a top down layout.
$(document).ready(function() {
$( ".mapjumpul li:nth-last-child(2)" ).append("<a id='mapjump2'></a>");
});
U should be able to do this with mediaqueries as well :
#mapjump2 {
display : none;
}
#media (min-height: 1000px) {
#mapjump2 {
display : inline;
}
}
I would do this with JQuery
<script>
var screen = $(window)
if (screen.width < 1000) {
$( ".mapjumpul li:nth-last-child(2)" ).append("<a id='mapjump2'></a>");
}
</script>

following navigation bar when scroll jquery

i have a jquery for the bar following when scroll down/up but it has delay
CSS
#rightbar_scroll {position: absolute;top: 0;right: 0;z-index: 10000; }
jQuery(document).ready(function(){
var jQuerysidebar = jQuery("#rightbar_scroll"),
jQuerywindow = jQuery(window),
offset = jQuerysidebar.offset(),
topPadding = 20;
jQuerywindow.scroll(function() {
if (jQuerywindow.scrollTop() > offset.top) {
jQuerysidebar.stop().animate({
marginTop: jQuerywindow.scrollTop() - offset.top + topPadding
});
} else {
jQuerysidebar.stop().animate({
marginTop: 0
});
}
});
});
i want it no delay, how do i add position like the box "Similar Questions" at the right side when ask question in this site?
Thank you, sorry my English not good
Try to use jQuery.css() instead jQuery.animate()
jQuerysidebar.css({
marginTop: jQuerywindow.scrollTop() - offset.top + topPadding
});
Change the position of #rightbar_scroll to fixed, if the page is scrolled >= offset.top
And don't forget to change it back to absolute, if the page is scrolled back again...

Conflict issue with jQuery functions

I've been scratching my head for a few days on this now. I have a site running a jcarousellite slider on the home page. On another page of the site I want the side nav to be sticky (i.e. be position: relative; whilst scrolling until it reaches the top of the page and then position: fixed; thereafter).
I have the following code being called in:
//jQuery Functions
$(document).ready(function(){
//JCarouselLite
$(function() {
$("#mainSlider").jCarouselLite({
btnNext: "#sliderBtnNext",
btnPrev: "#sliderBtnPrev",
visible: 1,
auto: 6000,
speed: 1000
});
});
//Sticky Side Nav
var stickerTop = parseInt($('#sticker').offset().top);
$(window).scroll(function() {
$("#sticker").css((parseInt($(window).scrollTop()) + parseInt($("#sticker").css('margin-top')) > stickerTop) ? {
position: 'fixed',
top: '0px'
} : {
position: 'relative'
});
});
});
In its current format, the sticky sidenav code is working fine, but jcarousellite is not. If I remove the sticky sidenav code, then jcarousellite works fine.
I'm sure this is going to be something simple like a syntax error but I just cant seem to solve it.
Any help much appreciated.
Use $ as function parameter for document ready
//jQuery Functions
jQuery(document).ready(function($){
//JCarouselLite
$(function() {
$("#mainSlider").jCarouselLite({
btnNext: "#sliderBtnNext",
btnPrev: "#sliderBtnPrev",
visible: 1,
auto: 6000,
speed: 1000
});
});
//Sticky Side Nav
var stickerTop = parseInt($('#sticker').offset().top);
$(window).scroll(function() {
$("#sticker").css((parseInt($(window).scrollTop()) + parseInt($("#sticker").css('margin-top')) > stickerTop) ? {
position: 'fixed',
top: '0px'
} : {
position: 'relative'
});
});
});

jcrop zoom, rotate, crop and resize later

http://hollywoodlacewigs.netsmartz.us/
I am working on above project.
user upload pic form 'upload' button and then 'select area' and then click 'mix' button.
this will show the cropped area onto other image.
click email link will compose two images.
But before that I want to let user 'rotate', 'zoom in/out' image before cropping the image.
am using jcrop, jquery ui draggable
here's the script :
$(document).ready(function() {
$('#UploadForm').change('submit', function(e) {
e.preventDefault();
$('#SubmitButton').attr('disabled', ''); // disable upload button
$('#left-pic').hide();
$('#output').show();
//show uploading message
$("#output").html('<img style="margin:45px 0px 0px 35px; " src="images/ajax-loader.gif" alt="Please Wait"/>');
$(this).ajaxSubmit({
target: '#output',
success: afterSuccess //call function after success
});
});
});
function afterSuccess(){
$('#UploadForm').resetForm(); // reset form
$('#SubmitButton').removeAttr('disabled'); //enable submit button
$('#cropbox').Jcrop({
aspectRatio: 1,
onSelect: updateCoords,
bgOpacity: 0.5,
bgColor: 'white',
addClass: 'jcrop-dark',
setSelect: [ 34, 50, 134, 155 ]
});
}
function updateCoords(c){
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
}
function checkCoords(){
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
}
$(function() {
$('#draggable3').draggable({
containment: $('#draggable3').parent(),
cursor: "move", cursorAt: { top: 56, left: 56 },
drag: function(event, ui) {
// Show the current dragged position of image
var currentPos = $(this).position();
// $("#xpos").text("CURRENT: \nLeft: " + (currentPos.left-580) + "\nTop: " + (currentPos.top-82));
$('#x3').val(currentPos.left-580);
$('#y3').val(currentPos.top-82);
}
});
});
You can use http://www.cropzoom.com.ar/demo/, I used and like it.
In IE exists one bug - fix is described on Draggable element in VML get stuck when size change (height, width) in IE 8
(I want to add answer in comment, but don't have permission)

Categories