Flexslider prev/next navigation appears below images in wordpress - javascript

I followed this article to enable flexsliderhttps://code.tutsplus.com/tutorials/adding-a-responsive-jquery-slider-to-your-wordpress-theme--wp-27914
I found they use font-awesome rather than image for the navigation and got it sorted out correctly.
However the prev/ next navigation are not showing up at their locations. I believe this has something to do with css.
Can someone guide me on how to fix this please?
I got the navigation appearing side by side after changing the
left:10px and right:10px to left:1px and right:1px for these class.
.flexslider:hover .flex-direction-nav .flex-prev {
opacity: 0.7;
left: 1px;
}
.flexslider:hover .flex-direction-nav .flex-next {
opacity: 0.7;
right: 1px;
}
Why could this kind of issue happen and what could the fix in css?
The image slider html
<div class="flexslider">
<ul class="slides">
<?php
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php // Check if there's a Slide URL given and if so let's a link to it
if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
<a href="<?php echo esc_url( get_post_meta( get_the_id(), 'wptuts_slideurl', true) ); ?>">
<?php }
// The Slide's Image
echo the_post_thumbnail();
// Close off the Slide's Link if there is one
if ( get_post_meta( get_the_id(), 'wptuts_slideurl', true) != '' ) { ?>
</a>
<?php } ?>
</li>
<?php endwhile; ?>
</ul><!-- .slides -->
</div><!-- .flexslider -->

There are too much missing informations for givin a precise answer, as there are only css for the two navigation buttons, but I guess it could have something to do with a parent position: (or sizing properties) property or something like that.

Related

How can I get the full height parallax images to stick to the top of the screen shrunk into stripes underneath each other?

I'm working on an animation. According to the plans, I should implement the following: 4 parallax images that fill the entire screen width and screen height (100vh, 100vw) are positioned one below the other (their number may change, since these images are preview images of galleries, and the user can add new galleries through the WordPress back end. I use ACF and CPT UI plugins, and I go through the posts' fields in PHP with a foreach loop). So the point would be that as you scroll down, the first parallax image sticks to the top, the next parallax image sticks 124px lower, and at the end, when you have already scrolled down completely, only 4 pieces of 124 px narrow strips remain from the full screen height images (100vh).
I wrote some JavaScript code, I looped through the image containers and I got the top position of each iteration with the getBoundingClientRect() method. The header is sticky and it's height is 62px, so I'm not checking if the top of the div has reached 0, but 62px. So when the first div with the image reaches 62px, it has to stop and stick, the second div has to stop at 62px + 124px (height of the strip that should remain of the full height image) and so on. I do not know what am I doing wrong, but now when the first image reaches the top, every image container disappears from the screen. I hope I have put it clearly and if someone can help, I would be very grateful.
HTML:
<?php
$posts = get_posts(array(
'posts_per_page' => -1,
'order' => 'ASC',
'post_type' => 'galleries'
));
if ($posts) :
?>
<?php foreach ($posts as $post) :
setup_postdata($post);
?>
<div class="gallery-preview-card" style="height: 100vh; background-image: url('<?php echo get_the_post_thumbnail_url(); ?>'); background-attachment: fixed; background-position: center; background-repeat: no-repeat; background-size: cover;" data-target="<?php the_permalink(); ?>" id="gallery-preview-card-id-<?php echo get_post_thumbnail_id($post); ?>">
<h3 class="gallery-title">
<?php echo the_title(); ?>
</h3>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
JS:
let galleryPrevs = document.querySelectorAll('.gallery-preview-card');
document.addEventListener('scroll', scroll, false);
function scroll(n) {
for (let i = 0; i < galleryPrevs.length; i++) {
let divTop = galleryPrevs[i].getBoundingClientRect().top;
if (divTop < 62 + 124 * i) {
galleryPrevs[i].style.position = 'fixed';
galleryPrevs[i].style.top = 62 + 124 * i;
}
}
}

How do I incrementally increase animation delay with vanilla JS for each post on in a wordpress theme

I have a php loop to show posts on a archive category page of a wordpress theme. I have also created an animation that takes the post from opacity=o to opacity=1 in .2s. I want to increase the delay of the animation for each additional post so the first post in the list appears a few milliseconds before the next post. I have already accomplished this using :nth-of-type(n) for a max post limit of 15. I know this is highly ineffective and would like to use (a loop?) JavaScript to handle animation delay with an incremental time increase.
#keyframes fade-in {
100% {
opacity: 1;
transform: translate(0, 0);
}
}
#section-grid a:nth-of-type(1) {
animation: fade-in .2s 0s forwards ease-out;
}
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div>
<img src="<?php the_field('feature_image2'); ?>" alt="plant">
<aside>
<?php the_title(); ?>
</aside>
</div>
</a>
<?php endwhile; else: ?>
<div class="page-header">
<h1>Coming Soon</h1>
</div>
<p>If there is nothing here that doesn't mean nothing is coming. Stay tuned for updates and new information.</p>
<?php endif; ?>
I would like for the animation delay to increase by .05s for each new post on an archive page. I would then be able to remove the :nth-of-type from my CSS.
Thanks in advance.
You can use inline css this way (the delay here is in milliseconds):
#section-grid a:nth-of-type(1) {
animation: fade-in .2s 0s forwards ease-out;
}
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$last_anim=0;
?>
<a href="<?php the_permalink(); ?>" style="animation:fade-in .2s .<?php echo $last_anim; ?>ms forwards ease-out;">
<div>
<img src="<?php the_field('feature_image2'); ?>" alt="plant">
<aside>
<?php the_title();
$last_anim+=500;
?>
</aside>
</div>
</a>
<?php endwhile; else: ?>
<div class="page-header">
<h1>Coming Soon</h1>
</div>
<p>If there is nothing here that doesn't mean nothing is coming. Stay tuned for updates and new information.</p>
<?php endif; ?>
I would suggest that you use a JavaScript library for this.
https://greensock.com/docs/TimelineMax/staggerTo
var elements = document.querySelectorAll('.js-animate');
TweenMax.staggerTo(elements, 0.2, {
autoAlpha: 1
}, 0.1);
Example: https://jsfiddle.net/qgkah26v/3/

Change Height of Div After Ajax Call

PROBLEM:
I have a dynamic form that is using JQuery steps to make it a wizard. Right now, there is a step where a drop down box selection triggers an AJAX call that then adds form fields to the form. I need the height of the div that this field is in to become longer based off of the amount of fields added.
IMAGES:
The form starts with two drop downs:
Once something is selected for the second dropdown, the AJAX call is made and the form appends fields.
The grey box should resize to accomodate the appended fields.
CODE:
The CSS for the div is as follows:
.wizard > .content
{
background: #eee;
display: table-cell;
margin: 0.5em;
min-height: 35em;
position: relative;
width: auto;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
I can add a permanent height here, but it's not dynamic.
The form is a Zend Form, so the HTML is as follows:
<div class="container-fluid">
<?php if ($this->error) : ?>
<div class="row-fluid">
<?php echo $this->error; ?>
</div>
<?php else : ?>
<?php echo $this->form()->openTag($form); ?>
<h3>Details</h3>
<section>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_NAME, false, true); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_DUE_DTTM, !($this->uberAdmin)); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_DESCRIPTION); ?>
</section>
<h3>Options</h3>
<section>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_REVIEW_PROJECT); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_WTL_PROJECT); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_JOB_TABLE); ?>
</section>
<h3>Project Configuration</h3>
<section>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_TYPES, !($this->uberAdmin), true); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_SUBTYPES, !($this->uberAdmin)); ?>
<?php
echo $this->partial('project/project/dynamicFormElements.phtml', array('form' => $this->projectForm, 'div' => 'project-config-elts'));
?>
</section>
<h3>Workflow Configuration</h3>
<section>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_WORKFLOW_TYPES, !($this->uberAdmin)); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_WORKFLOW_SUBTYPES, !($this->uberAdmin), true); ?>
<?php echo FormElementFactory::create($this, ProjectForm::KEY_PROJECT_WORKFLOW_CONFIG, !($this->uberAdmin)); ?>
</section>
This generates HTML with the structure below:
The highlighted div is the div in question.
My AJAX call is done here:
// Handle AJAX dynamic form creation results
function updateProjectForm(resp) {
$('div#project-config-elts').html(resp.html);
}
// Handle ajax error
function projectFormError(req, status, err) {
var errorString = '<div class="row-fluid alert alert-error">' +
'Error retrieving project form.' +
'</div>';
$('div#project-config-elts').html(errorString);
}
// AJAX request to get dynamic Project config form
function requestProjConfigForm() {
var request = {project_type: $('select[name=project_types]').val(),
project_subtype: $('select[name=project_subtypes]').val()
};
var ajaxOptions = {
url: 'projectform',
type:'POST',
dataType: 'json',
success: updateProjectForm,
error: projectFormError,
data: request
};
// Initiate the request!
$.ajax(ajaxOptions);
}
$('select[name=project_types]').change(function(){
updateProjectSubtypes();
});
// Handle a change in the selection of the particular project
$('select[name=project_subtypes]').change(function(){
requestProjConfigForm();
});
$('select[name=workflow_types]').change(function(){
updateWorkflowSubtypes();
});
$.validator.addMethod("validJSON", function(val, el) {
try {
JSON.parse(val);
return true;
} catch(e) {
return false;
}
}, "*Not valid JSON");
form.validate({
errorPlacement: function(error, element) {
$( element )
.closest( "form" )
.find( "label[for='" + element.attr( "id" ) + "']" )
.append( error );
},
rules: {
project_config: { validJSON: true }
}
});
I'm thinking that here I can dynamically change the height, but I'm not quite sure how to do so.
It looks like you're running into an issue that has been discussed on the jQuery Steps plugin github page: https://github.com/rstaib/jquery-steps/issues/147
basically, since the body of the step content is positioned absolutely with a percent height, it's height is no longer based on the content within it. A few things people used to try to fix this are:
By waqashsn:
.content > .body{
/*position: absolute*/
float:left;
width:95%;
height:95%;
padding:2.5%
}
Here's another alternative by AneeshRS that instead causes overflowing content to scroll:
.wizard.clearfix > .content.clearfix{
min-height: 500px;
overflow-y: auto;
}
Checkout the link to the issues page for a better explanation of either of these. Note however that any solution that involves removing the absolute positioning will likely cause transitions to no longer work.

change position depending on DB value

I let people fill in a form, and insert distances etc. They get stored in a db.
Then I lead them to a page, where I show the number of axles (12 in this case) and make a circle of them (in css)
Then it looks like this:
The code for this:
<?php
$show_axle = $database->axles($_GET['train_id']);
?>
<div id="axle_bogie_border">
<div id="axle_position">
<?php
foreach($show_axle as $axlefigure){ ?>
<div id='number_of_axles'> <?php echo $axlefigure['axle'] ?></div>
<?php
}
?>
</div>
</div>
The axle_border make the Train image (The black rectangle)
The axle_position take care that the axles (Numbers actually) Don't go in the image but slightly below it (So it looks like wheels/axles).
The Number_of_axles make the numbers look like a circle (Like wheels/axles).
Now the function:
function axles($id){
$sql = "SELECT * FROM axle WHERE train_id = :id2";
$sth = $this->pdo->prepare($sql);
$sth->bindParam(":id2", $id, PDO::PARAM_STR);
$sth->execute();
return $sth->fetchAll();
}
The function selects everything from the table axle (See first image).
Now, I actually want the axles to take a position. And I'm thinking about doing that via the Distance row.
So:
Axle 1 has the number 5 for distance. So it goes 5px from the far left
Axle 2 has the number 10. So i want it 10 pixels next to the axle 1.
Axle 3 has the number 5. So i want it 5 pixels next to the axle 2.
Etc.
Eventually it needs to look like this:
My question: Is this posible. If yes, how?
EDIT:
it is working now :)
I did the following:
<?php
$show_axle = $database->axles($_GET['train_id']);
?>
<div id="axle_bogie_border">
<div id="axle_position2">
<?php
foreach($show_axle as $axlefigure){ ?>
<div style="margin-left:<?php echo $axlefigure['distance'];?>px;">
<?php echo $axlefigure['axle'] ?>
</div>
<?php
}
?>
</div>
</div>
And the css:
#axle_position2 {
margin-top: 9%;
position: relative;
float: left;
}
#axle_position2 div {
background: green;
float: left;
position: inline-block;
width: 40px;
height: 40px;
border-radius: 50px;
}

Masonry settings not affecting WP post loop output

I am developing a WP 4.0 theme and trying to implement a simple setup of masonry. My intentions are to get a certain number of posts from a category, create a loop and have masonry lay them out in a dynamic grid.
For whatever reason, the settings I input (columnWidth and gutter) into my functions.js file seem to have no effect at all. All the images load up but only go down vertically in one column. I feel like either i'm missing something entirely or perhaps a small fluke somewhere?
functions.php:
function archive_grid(){
wp_enqueue_script('masonry');
}
add_action('wp_enqueue_scripts', 'archive_grid');
functions.js:
var container = document.querySelector('#masonry-loop');
var msnry = new Masonry( container, {
columnWidth: 300,
gutter: 30,
itemSelector: '.archive-container'
});
} );
template.php
<div id="archive-index">
<div id="masonry-loop">
<?php
$args = array(
'posts_per_page' => 6,
'category_name' => 'back-issue',
'orderby' => 'post_date',
'order' => 'DESC' );
$archive = get_posts( $args );
foreach ( $archive as $post ) : setup_postdata( $post ); ?>
<div class="archive-container">
<?php the_post_thumbnail(); ?></a>
</div><!-- Archive Container-->
<?php
endforeach;
?>
</div><!--/#masonry-loop-->
<?php
wp_reset_postdata(); ?>
</div><!-- #archive-index -->
It looks like this may be your problem (or at least part of it):
<div class="archive-container">
<?php the_post_thumbnail(); ?></a>
</div><!-- Archive Container-->
There's no opening < a > tag within the div :) Try adding that in and see if it fixes the column issue.
I'm not exactly sure where in my wordpress the images are being affected. It seems somewhere it is just ignoring masonry settings and setting the images to some other defined height which I cant seem to figure out but shows up in inspector as (img[Attributes Style] {};). I added some css attributes to the item containers to force the divs to max-widths. fixed the problem.
.archive-container {
max-width: 300px;
}
.item img {
width: auto;
height: auto;
max-width: 300px;
}

Categories