Viewer

Size
4,358 Kb
Views
4,048

How do I make an viewer?

What is a viewer? How do you make a viewer? This script and codes were developed by Adrien Clerbois on 30 December 2022, Friday.

Viewer Previews

Viewer - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Viewer</title> <link rel='stylesheet prefetch' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="action"> <a class="zoom-in">In</a> <a class="fit">Fit</a> <a class="zoom-out">Out</a> <div class="zoom-size">lll</div>
</div>
<div class="content"> <div class="wrapper"> <div class="spread"> <div class="left page"> <img class="thumb" src="http://footsalle-hainaut.be/img/test/page_1_thumb.jpg" /> <img class="full" src="http://footsalle-hainaut.be/img/test/page_1_large.jpg" /> </div> <div class="right page"> <img class="thumb" src="http://footsalle-hainaut.be/img/test/page_1_thumb.jpg" /> <img class="full" src="http://footsalle-hainaut.be/img/test/page_1_large.jpg" /> </div> <div class="markers"> <div class="marker marker-1"> </div> </div> </div> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Viewer - Script Codes CSS Codes

* { font-family: 'calibri';
}
.content { position: absolute; top: 0; left: 320px; right: 0; bottom: 0; padding: 0;
}
.content > .wrapper { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; position: absolute; top: 39px; border: 1px solid red; left: 0; right: 0; bottom: 0; overflow: auto;
}
.content > .wrapper div { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;
}
.content > .wrapper > .spread { position: absolute; cursor: hair;
}
.content > .wrapper > .spread > .page { position: absolute; width: 50%; height: 100%;
}
.content > .wrapper > .spread > .page.loaded > img { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;
}
.content > .wrapper > .spread > .page.loaded > img.full { display: block;
}
.content > .wrapper > .spread > .page.loaded > img.thumb { display: none;
}
.content > .wrapper > .spread > .page.right { right: 1px;
}
.content > .wrapper > .spread > .page > img { position: absolute; width: 100%; height: 100%; border: none; outline: none;
}
.content > .wrapper > .spread > .page > img.full { display: none;
}
.content > .wrapper > .spread > .page > img.thumb { display: block;
}
.content > .wrapper > .spread.single-page > .page.left { display: none;
}
.content > .wrapper > .spread.single-page > .page.right { width: 100%;
}
.content > .wrapper > .spread > .dummy { display: none;
}
.action { top: 0; left: 0 ; width: 320px; position: absolute; bottom: 0; padding: 0;
}
.action > a { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; display: block; text-align: center; margin: 30px auto; border: 2px solid black; width: 100px; cursor: pointer;
}
.action > a:hover { background-color: black; color: white;
}
.action .zoom-size { display: block; border: 2px solid black; margin: 30px auto; width: 100px; text-align: center;
}
.action .zoom-size:after { content: '%'; padding: 0 10px;
}

Viewer - Script Codes JS Codes

window.acl = {};
window.acl.leftPageWidthRealSize = 0;
window.acl.leftPageHeightRealSize = 0;
window.acl.rightPageWidthRealSize = 0;
window.acl.rightPageHeightRealSize = 0;
window.acl.currentRatio = 1;
window.acl.stepRatio = 0.1;
window.acl.maxRatio = 1;
var realSize = function(jQuerySelector){ // From https://css-tricks.com/snippets/jquery/get-an-images-native-width/ // Get on screen image var screenImage = jQuerySelector; // Create new offscreen image to test var theImage = new Image(); theImage.src = screenImage.attr("src"); // Get accurate measurements from that. return {width : theImage.width, height: theImage.height};
}
var fitRatio = function(){ var result = 0; var $wrapper = $('.wrapper'); var $spread = $wrapper.find('.spread'); var wrapperHeight = $wrapper.height(); var wrapperWidth = $wrapper.width(); var width = 0; var height = 0; var left = 0; var top = 0; if($spread.hasClass('single-page')){ var isLeftImage = !$('.left').hasClass('no-page'); var $selector; if(isLeftImage){ width = window.acl.leftPageWidthRealSize; height = window.acl.leftPageHeightRealSize; } else { width = window.acl.rightPageWidthRealSize; height = window.acl.rightPageHeightRealSize; } } else { width = (window.acl.leftPageWidthRealSize) + (window.acl.rightPageWidthRealSize); height = (window.acl.leftPageHeightRealSize > window.acl.rightPageHeightRealSize) ? window.acl.leftPageHeightRealSize : window.acl.rightPageHeightRealSize; } var ratioHeigh = wrapperHeight / height; var ratioWidth = wrapperWidth / width; return ratioHeigh > ratioWidth ? ratioWidth : ratioHeigh;
}
var zoom = function(ratio) { var $wrapper = $('.wrapper'); var $spread = $wrapper.find('.spread'); var wrapperHeight = $wrapper.height(); var wrapperWidth = $wrapper.width(); var width = 0; var height = 0; var left = 0; var top = 0; if($spread.hasClass('single-page')){ var isLeftImage = !$('.left').hasClass('no-page'); var $selector; if(isLeftImage){ width = window.acl.leftPageWidthRealSize * ratio; height = window.acl.leftPageHeightRealSize * ratio; } else { width = window.acl.rightPageWidthRealSize * ratio; height = window.acl.rightPageHeightRealSize * ratio; } } else { width = (window.acl.leftPageWidthRealSize* ratio) + (window.acl.rightPageWidthRealSize * ratio); height = (window.acl.leftPageHeightRealSize > window.acl.rightPageHeightRealSize) ? window.acl.leftPageHeightRealSize * ratio : window.acl.rightPageHeightRealSize * ratio; } $('.zoom-size').html((ratio * 100).toFixed(0)); // Center the spread left = (wrapperWidth - width) / 2; if(left < 0){ left = 0; } top = (wrapperHeight - height)/ 2; if(top < 0){ top = 0; } // Display the result $spread.width(width); $spread.height(height); $spread.css('left', left); $spread.css('top', top);
}
var zoomIn = function(){ window.acl.currentRatio += window.acl.stepRatio; if(window.acl.currentRatio > window.acl.maxRatio){ window.acl.currentRatio = window.acl.maxRatio; } zoom(window.acl.currentRatio);
}
var fit = function() { window.acl.currentRatio = fitRatio(); zoom(window.acl.currentRatio);
}
var zoomOut = function() { window.acl.currentRatio -= window.acl.stepRatio; if(window.acl.currentRatio <= 0.0001){ window.acl.currentRatio = window.acl.stepRatio; } zoom(window.acl.currentRatio);
}
var convert_to_percentage = function (el){ var parent = el.parent(); el.css({ left:parseInt(el.css('left'))/parent.width()*100+"%", top: parseInt(el.css('top'))/parent.height()*100+"%", width: el.width()/parent.width()*100+"%", height: el.height()/parent.height()*100+"%" });
}
var convert_to_percentage_drag = function (el){ var parent = el.parent(); el.css({ left:parseInt(el.css('left'))/parent.width()*100+"%", top: parseInt(el.css('top'))/parent.height()*100+"%", });
}
var setContainerSize = function (el) { var parent = $(el.target).parent().parent(); parent.css('height', parent.height() + "px");
}
var resetContainerSize = function (el) { parent.css('height', 'auto');
}
var resizeStop = function (event, ui){ convert_to_percentage($(this));
}
var dragStop = function (event, ui){ convert_to_percentage_drag($(this));
}
var setContainerResizer = function (event, ui) { console.log($(this)[0]); $($(this)[0]).children('.ui-resizable-handle').mouseover(setContainerSize); $($(this)[0]).children('.ui-resizable-handle').mouseout(resetContainerSize);
}
$(document).ready(function(){ if(!$('.page.right').hasClass('no-page')){ $('.page.right img.full').one('load', function(){ $('.page.right').addClass('loaded'); }).each(function() { if(this.complete) { $('.page.right').addClass('loaded'); } }); } if(!$('.page.left').hasClass('no-page')){ $('.page.left img.full').one('load', function(){ $('.page.left').addClass('loaded'); }).each(function() { if(this.complete) { $('.page.left').addClass('loaded'); } }); } // Get left real image size var leftRealSize = realSize($('.left img.full')); window.acl.leftPageWidthRealSize = leftRealSize.width; window.acl.leftPageHeightRealSize = leftRealSize.height; // Get right real image size var rightRealSize = realSize($('.right img.full')); window.acl.rightPageWidthRealSize = rightRealSize.width; window.acl.rightPageHeightRealSize = rightRealSize.height; zoom(window.acl.currentRatio); $('.zoom-in').on('click', function() { zoomIn(); }); $('.fit').on('click', function() { fit(); }); $('.zoom-out').on('click', function() { zoomOut(); }); fit(); $(window).resize(function(){ // fit(); });
});
$(document).ready(function(){ $('.marker').draggable({ scroll: true, containment: ".markers", stop: dragStop }); $('.marker').resizable({ containment: ".markers", create: setContainerResizer, stop: resizeStop });
});
Viewer - Script Codes
Viewer - Script Codes
Home Page Home
Developer Adrien Clerbois
Username AClerbois
Uploaded December 30, 2022
Rating 3
Size 4,358 Kb
Views 4,048
Do you need developer help for Viewer?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Adrien Clerbois (AClerbois) Script Codes
Create amazing SEO content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!