I'm working on my WordPress website with Visual Composer.
I need to include a pageable container but it would be great if it can be like a slideshow.
This is my pageable container
Thanks in advance,
Regards :)
Based upon the current version of WP Bakery Page Builder the below works for me:
To build it I created a row with 3 columns, with the pageable container in the middle column and the left and right arrow images in the columns on either side.
Both arrow images and the pageable container were given IDs. In my example the IDs of the arrows were #arrow_prev and #arrow_next respectively. You can give your pageable container any unique ID.
(function ($) {
$(document).ready(function(){
$( '#arrow_prev' ).click( function( e ) {
var pageable_container = $(this).closest(".vc_row").find(".vc_tta-panels-container");
move_pageable_container(pageable_container,'prev');
});
$( '#arrow_next' ).click( function( e ) {
var pageable_container = $(this).closest(".vc_row").find(".vc_tta-panels-container");
move_pageable_container(pageable_container,'next');
});
function move_pageable_container(pageable_container,direction){
// Make a list of the panel IDs
var panel_ids = $(pageable_container.find(".vc_tta-panel"))
.map(function() { return this.id; }) // convert to set of IDs
.get();
// Find position of the active panel in list
var current_active_pos = panel_ids.indexOf($(pageable_container).find(".vc_tta-panel.vc_active").attr('id'));
var new_pos = 0;
switch(direction) {
case 'prev':
if (current_active_pos > 0){
new_pos = current_active_pos-1;
}else{
new_pos = panel_ids.length-1;
}
break;
case 'next':
if (current_active_pos < panel_ids.length-1){
new_pos = current_active_pos+1;
}else{
new_pos = 0;
}
break;
}
// Clear active panels
$(pageable_container.find(".vc_tta-panel")).each(function(i,a) {
$(this).removeClass("vc_active");
});
var new_active_panel = $(pageable_container).find('#'+ panel_ids[new_pos]);
$(new_active_panel).addClass("vc_animating");
$(new_active_panel).addClass("vc_active");
setTimeout(
function(){
$(new_active_panel).removeClass("vc_animating");
}, 350);
}
}
);
})(jQuery);
If you want a pseudo fading-in effect then you can use this additional CSS in your style sheet:
#id_of_pageable_container .vc_tta-panel.vc_animating {
opacity: 0!important;
}
Where #id_of_pageable_container is the ID that you gave your pageable container
A simpler solution with vanilla js only:
The idea is to find the target page button and press it programmatically, so that there is no need to mimic the plugin's animations as in Chaz's solution.
Add js (via Raw JS widget / other means):
function prevSlide () {
const slides = document.getElementsByClassName('vc_pagination-item');
for (let i = 0; i < slides.length; i++) {
if (slides[i].className.includes('vc_active')) {
if (i - 1 < 0) return;
slides[i - 1].firstChild.click();
return;
}
}
}
function nextSlide () {
const slides = document.getElementsByClassName('vc_pagination-item');
for (let i = 0; i < slides.length; i++) {
if (slides[i].className.includes('vc_active')) {
if (i + 1 >= slides.length) return;
slides[i + 1].firstChild.click();
return;
}
}
}
Add button widgets and set href to call js:
For left arrow button,
javascript:prevSlide();
For right arrow button,
javascript:nextSlide();
Hope this helps.
I prefer to use the Post Grid widget for that. Keep in mind that the pageable container is not totally responsive, it doesn't react to swipe touching, but the Post Grid does.
Post Grid is really powerful, although it also has its caveouts. You can create your content with posts and pages, or a custom post type and then filter what you want to show in your slider from the widget options.
In "advanced mode" you can use the Grid Builder to create your own template and control the output.
The only problems that I've found with this method is to set a variable height in sliders and that sometimes it is slow loading content and is not possible to do a lazyload.
Related
I'm trying to make a fullpage component in Angular :
I want each sections take a 100% height of my screen, and when I scroll in a section (up or down) it goes to the next / previous section. I declared this function to do that, and it works :
#HostListener('wheel', ['$event'])
onScroll(event: WheelEvent) {
if (event.deltaY < 0) {
this.slidePrev();
} else {
this.slideNext();
}
}
Now, I want to update a little to slide to the previous slide only if the scrollbar is on the top, or slide to the next only if the scrollbar is to the bottom. I Used JQuery to do that, this way :
#HostListener('mousewheel', ['$event'])
onScroll(event: WheelEvent) {
if (this.isSliding) {
event.preventDefault();
return;
}
let $section = $(event.target).closest(".section");
//$section.css("opacity", "0.99");
//setTimeout(() => {
// $section.css("opacity", "1");
//}, 100);
if (event.deltaY < 0) {
if ($section.scrollTop() == 0) this.slidePrev();
} else {
if ($section.scrollTop() == $section.prop("scrollHeight") - $section.height()) this.slideNext();
}
}
It works the first time, but if I slide down to the next slide, when I want to sroll to move my scrollbar, it doesn't move.
I noticed that after the website trigger an update (example : css :hover event that update style) the scrollbar move again. So, if I uncomment my 4 commented lines, it works again because the style is updated.
Can someone tell me why ? And is there a better way to fix that issue ?
EDIT :
in slideNext() and slidePrev() I'm using $().animate("scrollTop", ...) function, and it's the function that breaks my scroll
note: I do not have access to the HTML or javascript code
I am using the excellent Chrome plugin, Web Override, to improve usability on a vendor site my company uses. I am only looking for CSS solutions (or possibly js/jq scripts I can sideload).
I'm trying to set table rows to highlight on hover, which is easy enough:
#task-list-main-table tr:hover {
background-color: lightyellow;
}
The problem is that there is a little button that appears on each row when you hover over it. This means if I hover over the button, the corresponding row is not highlighted.
Good:
Bad:
I know I could use pointer-events:none but then I can no longer click on the button, which I need to be able to do.
So, is there any way in CSS to "pass through" hover events without affecting click events?
This is a pretty convoluted method, but if you have the ability to inject javascript, this function will check if your mouse is overlapping whatever element you supply as the selector.
https://jsfiddle.net/tr_santi/aegybp6n/8/
//Change this value to desired element
var hoverElement = "td";
//Change this value to the class you'd like to add when hovering
var addClass = "hover";
function getOffset( el ) {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
}
function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}
function overlapListener(element, x, y, classToAdd) {
var eTop = getOffset(element).top;
var eLeft = getOffset(element).left;
var eBottom = eTop + element.clientHeight;
var eRight = eLeft + element.clientWidth;
if (x <= eRight && x >= eLeft && y <= eBottom && y >= eTop) {
if (!hasClass(element, classToAdd)) {
element.className = classToAdd;
}
} else {
if (hasClass(element, classToAdd)) {
element.className = "";
}
}
}
var elementList = document.querySelectorAll(hoverElement);
document.onmousemove=function(e){
[].forEach.call(elementList, function(b) {
overlapListener(b, e.clientX, e.clientY, addClass)
});
};
I'm sure there are some JS gurus around here that could write you something a bit less obfuscated, however I found this to be a good practice exercise for myself. I chose to write it in vanilla JS as I'm unsure of what your limitations are, although JQuery could substantially reduce the amount of needed code.
I have a funny trouble with CKEditor, it's described as below:
In CKEditor, I create a headline, an iframe or insert an image. It creates a "BORDER" around the content of the headline, iframe or image.
Now, I scroll the wheel of mouse up or down out of editor area, the "BORDER" still appears as below:
How I can remove this "BORDER"?
Please help me.
Thank in advance,
Vu
What you are seeing is IE native feature. Images, floated divs etc. get these resize borders.
IIRC any element which has hasLayout property will gain these resize handles.
In IE 8-10 there is possibility to block object resizing with - disableObjectResizing.
Unfortunately IE11 doesn't provide any handles to work around this problem. This is IE11 bug. There is a hack for IE11 which was not included into core code - https://dev.ckeditor.com/ticket/9317#comment:16.
Depending on method used for creating CKEditor, this hack can be for example implemented as follows:
If classic editor and replace method is used -
var editor = CKEDITOR.replace( 'editor1', {});
editor.on( 'pluginsLoaded', function( evt ){
editor.on( 'contentDom', function( e ){
var editable = editor.editable(),
element = editable.$;
if ( element.addEventListener ) {
// IE up to 10.
element.addEventListener( 'mscontrolselect', function( evt ) {
evt.preventDefault();
} );
} else {
// IE11 and higher.
element.attachEvent( 'oncontrolselect', function( evt ) {
evt.returnValue = false;
} );
}
});
});
If classic or inline editors are created automatically -
CKEDITOR.on( 'instanceCreated', function( event ) {
var editor = event.editor;
editor.on( 'contentDom', function( e ){
var editable = editor.editable(),
element = editable.$;
if ( element.addEventListener ) {
// IE up to 10.
element.addEventListener( 'mscontrolselect', function( evt ) {
evt.preventDefault();
} );
} else {
// IE11 and higher.
element.attachEvent( 'oncontrolselect', function( evt ) {
evt.returnValue = false;
} );
}
});
});
NOTE: Please also have a look at https://dev.ckeditor.com/ticket/9317#comment:26. There are other scenarios where resizing might get broken. It would be good to check if this hack works for all of them.
So, I have a media site built with wordpress that is using react js (something I would not suggest, as wordpress has its own way of doing things that doesn't always play nice with react). On this site I want to have a sidebar that dynamically loads elements of the sidebar (ads, recommended articles, social media buttons, etc), based on the height of the article that it is beside. These elements are react components themselves. So the way it all works, in my head that is, is the article component gets loaded onto the page first and when done, componentDidMount, it grabs the height of itself and sends it to the sidebar component. How that part happens is not important to my question, but its given to the sidebar component as a prop this.props.data.sidebarHeight). The sidebar then creates itself based on that height. It does so, or it should does so, recursively: if I have this much space left, well then I'll throw in an ad component, and then subtract the height of the ad component from my height and then check the new height all the way until I have not enough space left to add any more components (see . Bam dynamic sidebar. Here's my jsx code for the sidebar component:
var SidebarComponent = React.createClass({
recursivelyMakeSidebar: function(height, sidebar) {
// base case
if (height < 250 ) {
return sidebar;
}
if (height > 600) {
sidebar = sidebar + <AdvertisementSkyscraper />;
newHeight = height - 600;
} else if (height > 250) {
sidebar = sidebar + <AdvertisementBox />;
newHeight = height - 250;
}
return this.recursivelyMakeSidebar(newHeight, sidebar);
},
render: function() {
sidebarHeight = Math.round(this.props.data.sidebarHeight);
currentSidebar='';
sidebar = this.recursivelyMakeSidebar(sidebarHeight, currentSidebar);
return (
<div>
{sidebar}
</div>
)
}
}
);
// render component
React.render(
<SidebarComponent data={dataStore.sidebar} />,
document.getElementById('mn_sidebar_container')
);
It doesn't work. It returns [object Object] onto the DOM. Perhaps I don't understand react enough, but any thoughts on how to do this, if its actually possible, would be great.
The fundamental problem here is that you're concatenating components together as though they were strings of HTML, but they are actually functions. Pushing them into an array as functions will work. I also tweaked some of your compare operators to '>=' in the following example to make sure you don't get stuck in an endless loop.
var SidebarComponent = React.createClass({
recursivelyMakeSidebar: function(height, sidebar) {
if (height < 250 ) {
return sidebar;
}
if (height >= 600) {
sidebar.push(<p>600</p>)
height-=600
} else if (height >= 250) {
sidebar.push(<p>250</p>)
height-=250
}
return this.recursivelyMakeSidebar(height, sidebar);
},
render:function(){
var sidebarHeight = Math.round(this.props.data.height);
var currentSidebar = [];
var sidebar = this.recursivelyMakeSidebar(sidebarHeight, currentSidebar)
return <div>{sidebar}</div>
}
});
var sidebar = {height:900}
// render component
React.render(<SidebarComponent data={sidebar} />, document.body);
I am finally reaching out for help. I've been trying to get a no results message to show up on my Isotope image gallery for a week now, with only a little bit of luck. I had an example working at one point, but the message wouldn't hide until the animation was complete, so it didn't look good at all.
Surely someone has a solution.
I would greatly appreciate it if someone is able to help me. I have test site that I will link here in just a second.
For now here is the first half of my isotope configuration file. I have the '.message-div' placed at the bottom of my #isotopegallery div with css applying 'display: none;.'
jQuery(window).load(function() {
var $container = $('#isotopegallery').imagesLoaded(function() {
$container.isotope({
itemSelector: '.photo',
masonry: {
columnWidth: 161,
gutter: 10
},
transitionDuration: '0.6s'
});
// Filters
//
var filters = {};
$('#isotopefilters').on('click', '.menu-item', function() {
var $this = $(this);
// get group key
var $buttonGroup = $this.parents('.filter-title');
var filterGroup = $buttonGroup.attr('data-filter-group');
// set filter for group
filters[filterGroup] = $this.attr('data-filter');
// combine filters
var filterValue = '';
for (var prop in filters) {
filterValue += filters[prop];
}
$container.isotope({filter: filterValue});
// Possibility
$container.isotope( 'on', 'layoutComplete',
function( iso, laidOutItems ) {
if ( laidOutItems < 1 ) {
$('.message-div').fadeIn('slow');
} else {
$('.message-div').fadeOut('fast');
}
})
});
});
});
There is an easy workaround to achieve the "no result" message.
Consider ".photo" as class for the itemSelector. As isotope is simply attaching ".isotope-hidden" to the div-container if it does not match the filter, the number of these divs equals the total of all isotope items in case of "no result". Easy:
if($(".isotope-hidden").length == $(".photo").length) {
$("#mynoresults").show();
}