Slider Loads each slide before rendering correctly - javascript

If you look at my URL below, and on a connection that may not be really speedy. You'd notice the slider at the top, loads each individual slide in a vertical list (Taking about 1000px space) before snapping into the way it's supposed to render - which is like a standard slider; displaying and sliding one slide at a time.
Does anyone have any suggestions as to how to allow my slider to load correctly?
Live site at >> http://tinyurl.com/cz6sawg
--- Thanks for any pointers, I'm thinking I need to find a script that allows the slides to be hidden until the slider / page is fully loaded before presenting them.
Relevant jQuery:
<script type="text/javascript">
jQuery(document).ready(function($){
$("#photo-rotator").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 6000);
});
</script>
Relevant Mark-Up:
<!-- Top of Page Slider FRAGILE -->
<div style="min-height: 280px;">
<div id="photo-rotator" style="">
<?php $slide_id=1; ?>
<?php
$featuredPosts = new WP_Query();
$featuredPosts->query("showposts=3");
while ($featuredPosts->have_posts()) : $featuredPosts->the_post();
?>
<div id="slide-<?php echo $slide_id; $slide_id++;?>">
<a href="<?php the_permalink() ?>" class="post-image">
<?php the_post_thumbnail( 'rotator-post-image' ); ?>
<span class="title" style="font-style:italic; color:#999;"><?php the_title(); ?></span>
</a>
</div>
<?php endwhile; ?><!--/close loop-->
<ul id="slide-nav">
<?php $nav_id=1; ?>
<?php while ($featuredPosts->have_posts()) : $featuredPosts->the_post(); ?>
<li>
<a href="#slide-<?php echo $nav_id; ?>">
<span class="thumbnail" style="display:none;">
</span>
<p style="color:#F93; font-family:Georgia, 'Times New Roman', Times, serif; font-size: 18px;"><? the_title(); $nav_id++;?></p>
<div style="">
<!--<?php the_excerpt(); ?>-->
<?php if($text= get_post_meta($post->ID, "slidetext", true)) { ?>
<div class="">
<p style="font-weight: normal; color: #333; font-family: Arial, Helvetica, sans-serif; font-size: 14px;"><?php echo $text; ?></p>
</div>
<?php } //else { print"<div>"; } ?>
</div>
</a>
</li>
<?php endwhile; ?><!--/close loop-->
</ul>
</div>
</div>
<!-- End Top page Slider FRAGILE -->

Your code is a bit messy, and the question does not help, but in relation to the part of your question where it reads:
ou'd notice the slider at the top, loads each individual slide in a vertical list (Taking about 1000px space) before snapping into the way it's supposed to render
You can wrap the entire slider content with a div and give overflow:hidden; to prevent the height of +/-1000px on the page load:
CSS
#photo-rotatorWrapper {
width: 960px;
height: 400px;
margin: 0 auto;
overflow: hidden;
}
HTML
<div id="photo-rotatorWrapper">
<div id="photo-rotator">
...
</div>
</div>
Note:
You may need to set other CSS declarations for that wrapper in order to stay positioned correctly within your current HTML structure.

Related

Cannot copy text from div when timer is refreshing it

I have a chat with setInterval and it's refreshing a div (where messages are), but the problem is when i select the message with my mouse (blue marker) and for example i want to copy something from it, the timer refreshes the chat div and it won't let me do that. It automaticly disables the marked text, i hope you understand me what i'm talking about.
setInterval('test()', 1000);
function test(){
$('#chatbox').load('load.php?chat_refresh');
$("#online-users-text").load(location.href+ ' #online-users-text');
<?php
$query_chat = $handler->query('SELECT * FROM users');
while($ch = $query_chat->fetch()){
if($ch['status'] == 1){
?> Chat_Refresh(); <?php
}
}
?>
}
As you can see in the code, timer is calling function test() after every second, and that function is calling $('#chatbox').load('load.php?chat_refresh'); which is refreshing load.php?chatrefresh from another page:
if(isset($_GET['chat_refresh'])){
$query = $handler->query('SELECT * FROM (SELECT * FROM chat ORDER BY id DESC LIMIT 15) AS chat ORDER BY id ASC');
while($r = $query->fetch()){
$strText = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '<span style="text-decoration: underline;">\0</span>', showBBcodes($r['message']) );
?>
<?php if(empty($r['owner'])){ ?> <!-- Clear chat -->
<div class="chat-body clearfix">
<div class="header">
<span style="line-height: 40px; visibility: hidden;">test</span>
</div>
</div>
<?php }else{ ?>
<ul class="chat"> <!-- Show chat -->
<li class="left clearfix">
<span class="chat-img pull-left">
<img src="<?php echo BASE_URL, $r['avatar']; ?>" class="img-thumbnail" width='40' height='40' />
</span>
<div class="chat-body clearfix">
<div class="header">
<span style="line-height: 40px; color: #737373;">
<b><?php echo $r['owner']; ?></b>:</span> <span class="text"><?php echo parseSmiley($strText); ?></span> <small style="line-height: 40px; margin-right: 5px;" class="pull-right text-muted"><i class="fa fa-clock-o"></i> <?php echo $r['created']; ?></small>
</div>
</div>
</li>
</ul>
<?php }
}
}
When i go to google chrome console, i can clearly see that timer is refreshing #chatbox div and that div is blinking.

How to make an image slider with dynamic content

How can I make a content slider, like the popular product sliders shown on most websites (Flipkart, Amazon), which scroll left and right on button click, similar to this image:
I have only four contents showing, but I want to add some more, and I want it to slide on button click. Sorry, I dont know the exact term for it.
These content values would be dynamic.
<div class="dialog">
<div class="shop_img">
<img src="../image/shops/1.jpg">
</div>
<hr id="hr">
<div class="shop_name">
<?php echo $name;?>
</div>
<a href="detail.php?add=<?php echo $add_id;?>"><div class="address">
<span id="1">ADDRESS</span><span id="2"><i class="fa fa-arrow-right" aria-hidden="true"></i></i></span>
</div></a>
</div>
This is called carousel.
You can use a javascript plugin called owl carousel from here http://www.owlcarousel.owlgraphic.com/ to achieve that effect.
You can use php foreach loop to dynamically generate your carousel items inside carousel container like below:
<?php
foreach ($items as $key => $item) {
ob_start();
?>
<div class="dialog">
<div class="shop_img">
<img src="../image/shops/<?php echo $item->imageName;?>">
</div>
<hr id="hr">
<div class="shop_name">
<?php echo $item->name;?>
</div>
<a href="detail.php?add=<?php echo $item->id;?>"><div class="address">
<span id="1">ADDRESS</span><span id="2"><i class="fa fa-arrow-right" aria-hidden="true"></i></i></span>
</div></a>
</div>
<?php
$itemHtml = ob_get_clean();
print $itemHtml;
}
?>

Expand/collapse excerpt and content

Setting up a simple WordPress blog, that only contains a single page wich is the blog archive. But i have run in to a problem, i want to have a toggle the excerpt and content show more/show less functionality, så that visitors easy can go trough the posts on the same page without page reloads or beeing sent to the single post page. I know this has been asked here before but none of those examples works for me. Just want a simple show/hide functionality to show the excerpt automatic and when users click show more, the whole post slides open to show complete content, and when they click show less, the post goes back to excerpt. I tried most that is here on stack but nothingworks so now i rolled back to my original files to start over. So this script does nothing right now as you se in the loop-custom file. But this is what i have tried.
Here is my js:
$(function () {
$('.mainContent').hide();
$('a.read').click(function () {
$(this).parent('.excerpt').slideUp('fast');
$(this).closest('.post').find('.mainContent').slideDown('fast');
// $('.mainContent').show();
return false;
});
$('a.read-less').click(function () {
$(this).parent('.mainContent').slideUp('fast');
$(this).closest('.post').find('.excerpt').slideDown('fast');
return false;
});
});
Here is my index file:
<div id="content">
<div id="inner-content" class="row">
<main id="main" class="large-8 medium-8 columns" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!-- To see additional archive styles, visit the /parts directory -->
<?php get_template_part( 'parts/loop', 'custom' ); ?>
<?php endwhile; ?>
<?php joints_page_navi(); ?>
<?php else : ?>
<?php get_template_part( 'parts/content', 'missing' ); ?>
<?php endif; ?>
</main> <!-- end #main -->
<?php get_sidebar(); ?>
</div> <!-- end #inner-content -->
</div> <!-- end #content -->
And here is my loop-custom file:
<article class="post" id="post-<?php the_ID(); ?>" <?php post_class(''); ?> role="article">
<header class="article-header">
<?php get_template_part( 'parts/content', 'byline' ); ?>
<h2><?php the_title(); ?></h2>
</header> <!-- end article header -->
<section class="entry-content" itemprop="articleBody">
<?php the_post_thumbnail('full'); ?>
<?php the_excerpt('<button class="tiny">' . __( 'Show more...', 'jointswp' ) . '</button>'); ?>
</section> <!-- end article section -->
EDIT: Answer updated after testing in fiddle.
<div class="post-wrap">
<h2>The Title</h2>
<div class="post">
<div class="excerpt">
Excerpt goes here
</div>
<div class="whole-post">
Slidey read more content goes here
</div>
Read More
</div>
</div>
.whole-post {
display: none;
}
.post {
position: relative;
padding-bottom: 50px;
}
a.read {
position: absolute;
bottom: 10px;
right: 10px;
}
$('a.read').click(function () {
$(this).siblings('.excerpt').slideToggle(500);
$(this).siblings('.whole-post').slideToggle(500);
});
Further comment asking about changing "read more" button text on click - requires additional line of jQuery, like so:
$('a.read').click(function () {
$(this).siblings('.whole-post').is(':visible') ? $(this).html('Read More') : $(this).html('Read Less');
$(this).siblings('.excerpt').slideToggle(500);
$(this).siblings('.whole-post').slideToggle(500);
});
jsfiddle here.
Note: The ternary query ? truthy : falsey ; syntax is short for if (query) { truthy } else { falsey } ;
You can try to use this plugin: https://wordpress.org/plugins/wp-showhide

Making a <div> Clickable in Wordpress

I'm working on modifying an existing wordpress portfolio page. All that is left to do is to make it so when the user clicks anywhere in the article list the link will open. Currently it is just when the title or image is clicked.
I can see that I could make a clickable with the following setup:
<a href="http://example.com">
<div>
anything
</div>
</a>
However Wordpress moves the tags when the page loads like so:
<a href="http://example.com">
</a>
<div>
anything
</div>
So I started to work on using css with the following setup:
HTML
<div class= "box">
</div>
CSS
div.box {
position: relative;
}
div.box:hover {
cursor: hand;
cursor: pointer;
opacity: .9;
}
The hover works, it triggers over all of the content and a cursor does appear.
However thats as much as I can do so far. Any attempt to interact with the .box is shot down. Nothing will trigger with javascript using the following :
$(".box").click(function() {
alert("I am an alert box!");
});
I cannot seem to interact with the div.
The page is as follows:
<div class= "box">
<article id="post-<?php the_ID(); ?>" class="portfolio-article clearfix">
<?php if( get_post_meta($post->ID, "portfolio_image", true) ): ?>
<img src="<?php the_field('portfolio_image'); ?>" class="portfolio-image">
<!--get PDF if not empty-->
<?php else: ?>
<img src="http://domain.com/wp-content/uploads/2014/02/placeholder.png" class="portfolio-image">
<?php endif; ?>
<div class="portfolio-content">
<header>
<?php if( get_post_meta($post->ID, "portfolio_link", true) ): ?>
<h1 class="portfolio-title">
<a target="_blank" href="<?php the_field('portfolio_link'); ?>">
<?php the_field('portfolio_title'); ?> <span class="sosa-icon">p</span>
</a>
</h1>
<!--get PDF if not empty-->
<?php else: ?>
<h1 class="portfolio-title"><?php the_field('portfolio_title'); ?></h1>
<?php endif; ?>
</header>
<p class="portfolio-meta">
<?php the_field('portfolio_publication_and_date'); ?>
<?php if( get_post_meta($post->ID, "portfolio_pdf_upload", true) ): ?>
<span class="sosa-icon">H</span> Open Pdf<!--get PDF if not empty-->
<?php endif; ?>
</p><!-- END ortfolio-meta -->
</div><!--portfolio-content-->
</article>
</div>
NewToJS was in the right area when saying it could be a problem with the access to the jQuery library. In this case I had linked jQuery correctly, it was tested and working.
jQuery in Wordpress needs to be enqueued by adding the following into functions.php
wp_enqueue_script("jquery");
My fault was because I didn't change the '$' to 'jQuery' as this is necessary when working with Wordpress.
Here is the incorrect usage :
$(".box").click(function() {
alert("I am an alert box!");
});
Here is the correct usage :
jQuery(".box").click(function() {
alert("I am an alert box!");
});

Slides not showing on flexslider

I'm building a new homepage WordPress template. The template uses Flexslider to display Vimeo videos, a simple title and description.
I've followed the FlexSlider documentation to the letter, but the slides are all coming up blank.
Here's what I'm seeing via the Chrome Inspector:
.flexslider .slides > li {
display: none;
-webkit-backface-visibility: hidden;
}
For some reason the JQuery isn't kicking in. I've tried removing the inline styles from the <li> tags. I've also tried knocking out the lightbox script that I have running. Nothing seems to be working.
Can you see what's causing this? I've uploaded a demo here: http://bit.ly/1Sgpu99
UPDATE
Here's the relevant source from the template:
<?php // Begin main loop
while ( have_posts() ) : the_post(); ?>
<?php // Begin carousel repeater
if( have_rows('slides') ): ?>
<div class="flex-container">
<div class="flexslider">
<ul class="slides">
<?php while( have_rows('slides') ): the_row();
// vars
$background_image = get_sub_field('background_image');
$video = get_sub_field('video');
$title = get_sub_field('title');
$description = get_sub_field('description');
$background_image = get_sub_field('background_image');
?>
<li class="slide" style="background: url(<?php echo $background_image; ?>) no-repeat center; background-size: cover;">
<div class="container">
<div class="half">
<div class="video"><?php echo $video; ?></div>
</div>
<div class="half last">
<header class="entry-header">
<h1 class="entry-title"><?php echo $title; ?></h1>
</header>
<?php echo $description; ?>
</div>
</div><!-- .container -->
</li>
<?php endwhile; ?>
</ul>
</div><!-- .flexslider -->
</div><!-- .flex-container -->
<?php // End repeater
endif; ?>
<?php // End main loop
endwhile; ?>
For some reason flexslider has not been initialized in your page.
If you put this code in Chrome or Firefox console
jQuery(".flexslider")
.flexslider({
animation: "slide",
useCSS: false,
animationLoop: false,
smoothHeight: true,
before: function(slider){
$f(player).api('pause');
}
});
and hit enter, the slider is showing ( whit completely broken css, but this is another question :) )
I can't tell from provided code why slider is not initialized, but you must debug your .js code, not .php. Put some console.log() in .js file where slider is initialized, to be sure that file is loaded, use wp_enqueue_script() to load your .jsfiles with proper dependence to be sure that files are loaded in proper order and so on.

Categories

Resources