How define the img src path in MVC - html

I have my index.cshtml with a image
< img id="u3430_img" src="Images/send.png">
And a folder Images inside myApp/Images folder
if i access
http:/localhost/myApp OR
http:/localhost/myApp/home/
works Ok. But if i use
http:/localhost/myApp/home/index
The page try to look for the image in
http:/localhost/myApp/home/Images/send.png
So how I should define my src.
Aditional note:
Beside the index.cshtml I also have an js file where a hover effect is add it to the image. And have same problem neither of those option work
$('#u3430_img').hover(
function () {
$(this).attr("src", "~/Images/send_hover.png");
},
function () {
$(this).attr("src", "Images/send.png");
}
);

You can reference images in the top level of the project with the ~.
<img src="~/Images/send.png">
Older versions of ASP.NET MVC needed a #Url.Content() around the path, as described here
Edit: If you want to update the path from Javascript, you can either specify an absolute path, or wrap it in #Url.Content().
$('#image').attr('src', '/Images/send.jpg');
$('#image').attr('src', '#Url.Content("~/Images/send.png")');

in Cshtml page adding ~ is not necessary.Just add /Images/send.png ...It will come to root and follow hierarchy.

Related

iframe with srcdoc: same-page links load the parent page in the frame

Same-page links work by referencing another element that has id="sec-id" on the same page, using
for instance. A link like this is relative.
However, if I use that very same syntax in the iframe in my LaTeX.js playground, it will not just scroll to the destination element, but (re)load the whole playground page inside the ifame. (Note that I set the contents of the iframe programmatically with iframe.srcdoc = html)
Example: LaTeX.js playground, right at the end of the first section click on the link in "See also SecĀ­tion 11." in the iframe on the right side.
What could be the reason?
UPDATE: I now understand the source of the problem: the browser uses the document's base URL to make all relative URLs absolute (see <base>). The trouble starts with an iframe that has its content set with srcdoc: no unique base URL is specified, and in that case the base URL of the parent frame/document is used--the playground in my case (see the HTML Standard).
Therefore, the question becomes: is there a way to reference the srcdoc iframe in a base URL? or is it possible to make the browser not prepend the base? or to make a base URL that doesn't change the relative #sec-id URLs?
I don't know exactly how you could resolve this, I think it is because the srcdoc, you can't use the src with the content-type because the character limit, but you can convert it to a Blob and it kinda works, the style are lost though. Maybe you can use it as a starting point, based on your page:
// Get the document content
const doc = document.querySelector('iframe').srcdoc;
// Convert it to blob
const blob = new Blob([doc], {type : 'text/html'});
// Load the blob on the src attr
document.querySelector('iframe').src = URL.createObjectURL(blob);
// Remove srcdoc to allow src
document.querySelector('iframe').removeAttribute('srcdoc');
What about catching the event and scrolling to the desired anchor?
$("a").click(function(e) {
$('.iframe').animate({
scrollTop: $(e.target.attr('href')).offset().top
}, 2000);
return false;
});
For the record, it seems that my question is not possible, i.e., it is not possible to use relative same-page links in an iframe that has its content set using srcdoc. A workaround has to be used, see the other answer.

What is wrong with path in gulp.spritesmith?

I used gulp.spritesmith to make a sprite image. I imported sprite.sass into main.sass and it seems to be working except there is a problem with path to images. I know it is probably some silly mistake but I can't figure out what it is so I would be really greatful if you can help me.
Here is my gulpfile fragment
gulp.task('sprite', function () {
var spriteData = gulp.src('assets/img/icons/*.png').pipe(spritesmith({
imgName: 'sprite.png',
cssName: 'sprite.sass',
imgPath: './assets/img/sprite.png'
}));
spriteData.css.pipe(gulp.dest('./assets/sass/1-tools'));
});
I'm including image
.services-item
&-design
#include sprite($heart-services)
And these is how it works in the browser.
Here is my project structure
It's been nearly 2 years. Hope you have already solved it. AFAIK, among these options of spritesmith, **imgPath ** is the request path relative to the css file rather than the project structure of SASS/images source.
Suppose your css file containing your sprite image reference is in folder ./assets/sass/, and your image is in ./assets/img/. In this case you can try change the imgPath option to:
imgPath: '../img/sprite.png' //use .. back to assets folder, then go down to img folder

ng-src not showing up for my img array

I have a simple image viewer webpage on gitpages but before I push the next group of images I want to condense all of my images into an array using angular.
The test I have made here uses only 4 photos that are in the same folder as every other file.(they are jpegs)
my js file is set up like this with a factory for the array and a controller.
angular.module('beamModule',[])
.factory('imageFactory', function(){
return {
getImages: function(){
return ['beam1.jpg','beam2.jpg','beam3.jpg','beam4.jpg'];
}
}
})
.controller('Photos', function(imageFactory){
this.images = imageFactory.getImages();
});
I don't think anything is wrong with this array but maybe I am overlooking something?
The HTML that I am using and the section that is giving me trouble when I check the developer tools is below.
<div class="imgcontainer" ng-controller="Photos as photosController">
<img ng-repeat="src in photosController.images"
ng-src="beamModule.js/{{images}}">
</div>
I am not sure if I am supposed to be using an ng-class attribute in the css or if there is something else that needs removed?
The developer tools are returning this value for each of the images (they are repeating just not showing)
<img ng-repeat="src in photosController.images" class="ng-scope">
Why is the ng-scope class being put in here and the ng-src is being removed?
EDIT FIXED
Ok to the person who answered so quickly and simply you are the real mvp here.
You said to change the ng-src="beamModule.js/{{images}}" to read {{src}} instead.
Once I tried this it still didnt work but then I checked the dev tools and noticed it was attempting to pull the files from the js file and not the actual file so I just changed it to this and now it works great! Thank you.
ng-src="{{src}}"
The ng-src attribute needed to point to the repeat instead of the js file.
ng-src="{{src}}"

Joomla Custom Html Module How too link img code

I have the following as the html code to display a circular image with animation, how do I link the actual image file, have tried the a-href function but not linking, codes used is as below:
[feature bgcolor="#5cc2e5" textcolor="white" border="false" img="images/feature/01.jpg"]
Example can be seen at: http://www.envande.com/index.php
Thanks.
You can make the entire div clickable using this jQuery code:
jQuery(".feature-rounded").click(function() {
window.location = jQuery(this).find("a").attr("href"); // use link from readmore button
return false;
});
As an alternative, have you tried wrapping your code inside an <a href... tag? (I assume you're using a plugin to generate the HTML output seen on your website) :
[feature bgcolor="#5cc2e5" textcolor="white" border="false" img="images/feature/01.jpg"]

EmberJS set active class for dynamic linkTo on menu when direct accessed

i've been trying this since last week, to make the active class work on those dynamic links:
<li>{{#linkTo tag 'bw'}}Black and White{{/linkTo}}</li>
<li>{{#linkTo tag 'instax'}}Instax{{/linkTo}}</li>
<li>{{#linkTo tag 'digital'}}Digital{{/linkTo}}</li>
I put a code running here: http://jsbin.com/opuzop/1/edit so if you feel ok to help me with that would be great :D it's my photo portfolio as well.
Also, if I try to upload to the newer version of Ember, some stuff stop to work, like the JS I created on
App.GeneralView = Ember.View.extend({
didInsertElement: function() {
if(this.$() !== undefined){...
It was created to load after the view render, so I do a image resize and a body resize too, and set everything horizontal, but with the newer version it only work when accessed directly.
Also, sometimes it don't get the JSON from Tumblr and stop working.
I'm not sure, but I think it has to do with the serialization of your object, try adding something like this in your "App.TagRoute" route:
serialize: function(param) {
return {tag: param.tag}
}